【问题标题】:Polar plot in Matplotlib using contourf plots incorrect rangeMatplotlib 中的极坐标图使用 contourf 绘制不正确的范围
【发布时间】:2017-03-18 06:12:57
【问题描述】:

我正在绘制一些在球坐标中运行的流体动力学模拟数据,有时我更喜欢使用 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()

有没有快速解决办法?谢谢

【问题讨论】:

    标签: matplotlib contourf


    【解决方案1】:

    可以设置坐标轴范围。径向刻度设置为y,因此

    ax.set_ylim(0,1) 
    

    将原点设置为 0。

    【讨论】:

      猜你喜欢
      • 2017-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 2015-11-03
      • 2017-05-03
      相关资源
      最近更新 更多