我正在绘制一些以球坐标运行的流体动力学模拟数据,有时更喜欢在pcolormesh上使用contourf,因为它看起来很漂亮而不是像素化。但是,我注意到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()
有快速解决方法吗?感谢