Matplotlib中使用轮廓图的极坐标图范围不正确

Matplotlib中使用轮廓图的极坐标图范围不正确,matplotlib,contourf,Matplotlib,Contourf,我正在绘制一些在球坐标系下运行的流体动力学模拟数据,有时我更喜欢使用contourf而不是pcolormesh,因为它看起来很漂亮、平滑,而不是像素化。然而,我注意到,在极坐标图中,contourf总是将我的数据扩展到r=0,但我的数据从不包括r=0。我用下面的简单例子再现了这个问题: from pylab import * fig = figure(figsize=(6, 6)) ax = fig.add_subplot(111,projection='polar') # gener

我正在绘制一些在球坐标系下运行的流体动力学模拟数据,有时我更喜欢使用contourf而不是pcolormesh,因为它看起来很漂亮、平滑,而不是像素化。然而,我注意到,在极坐标图中,contourf总是将我的数据扩展到r=0,但我的数据从不包括r=0。我用下面的简单例子再现了这个问题:

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()

有快速解决办法吗?谢谢

可以设置轴限制。径向刻度设置为
y
,因此

ax.set_ylim(0,1) 
将原点设置为0