2017-03-18 44 views
0

我繪製球面座標運行一些流體動力學模擬數據,有時更喜歡pcolormesh使用contourf,因爲它看起來不錯,順利的,而不是像素化。但是,我注意到contourf總是將我的數據在極座標圖中擴展到r = 0,但我的數據從不包含r = 0。我使用下面的簡單示例重現了此問題:極座標圖使用contourf地塊不正確範圍

from pylab import * 

fig = figure(figsize=(6, 6)) 
ax = fig.add_subplot(111,projection='polar') 

# generate some data 
Nt,Nr = 150,150 
r_axis = np.linspace(0.5,1.,Nr) 
t_axis = np.linspace(0.,0.5*np.pi,Nt) 
r_grid, t_grid = np.meshgrid(r_axis,t_axis) 

data = np.zeros((Nt,Nr)) 
sin_theta = np.sin(t_axis) 
for i in range(Nr): 
    data[:,i] = sin_theta 

if 1: # polar plot using contourf - plots incorrectly from r = 0 
    scale = np.linspace(0.,1.,100) 
    polar = ax.contourf(t_grid,r_grid,data,scale,cmap='Spectral') 
else: # correctly plots the data 
    polar = ax.pcolormesh(t_grid,r_grid,data,cmap='Spectral') 
show() 

是否有快速修復?感謝

回答

0

一個可以設置軸限制。徑向標尺被設置爲y,因此

ax.set_ylim(0,1) 

將原點設定爲0。

enter image description here