Matplotlib:set_rmin 不适用于对数极坐标投影
Matplotlib: set_rmin not working for logarithmic polar projection
我正在尝试在极坐标投影中绘制网格数据。但是,我需要在 Y (r) 轴上设置最小值,但 set_rmin() 似乎不起作用 - 不管输入的值如何,绘图都不会改变。
另外,小问题,有谁知道如何在实际颜色图上绘制网格?到目前为止,我已经通过手动画圈来修复它,但这似乎很不优雅。
干杯
附上脚本的绘图部分:
ax1 = plt.subplot(gs[x,y], projection="polar")
ax1.set_theta_zero_location('N')
ax1.set_theta_direction(-1)
ax1.set_rmin(0.5)
ax1.set_rscale('log')
im=ax1.pcolormesh(theta,r,dataMasked.T, vmin = 0.5, vmax = vmax_,cmap='spectral')
im.cmap.set_bad('w',1.)
ax1.set_yticks(range(0, 90, 15))
ax1.yaxis.grid(True)
您应该在 设置 ax1.set_rscale('log')
之后设置 ax1.set_rmin(0.5)
。您可能还需要将 ax1.set_rmax()
设置为适当的值。
编辑:
看来你需要先设置rscale = log
,然后设置rmax
,再设置rmin
,否则不行:
In [1]: import matplotlib.pyplot as plt
In [2]: ax1 = plt.subplot(111, projection="polar")
In [3]: ax1.get_rmin(), ax1.get_rmax()
Out[3]: (0.0, 1.0) # Looks ok
In [4]: ax1.set_rmin(0.5)
In [5]: ax1.get_rmin(), ax1.get_rmax()
Out[5]: (0.5, 1.0) # Looks ok
In [6]: ax1.set_rscale('log')
In [7]: ax1.get_rmin(), ax1.get_rmax()
# Setting rscale=log changes both rmin and rmax
Out[7]: (9.9999999999999995e-08, 1.0000000000000001e-05)
In [8]: ax1.set_rmin(0.5)
In [9]: ax1.get_rmin(), ax1.get_rmax()
# OK, so that didn't work, because we were trying to
# set rmin to a value greater than rmax
Out[9]: (1.0000000000000001e-05, 0.5)
# Set both rmax and rmin (rmax first)
In [10]: ax1.set_rmax(1); ax1.set_rmin(0.5)
In [11]: ax1.get_rmin(), ax1.get_rmax()
Out[11]: (0.5, 1.0) # Success!
我正在尝试在极坐标投影中绘制网格数据。但是,我需要在 Y (r) 轴上设置最小值,但 set_rmin() 似乎不起作用 - 不管输入的值如何,绘图都不会改变。
另外,小问题,有谁知道如何在实际颜色图上绘制网格?到目前为止,我已经通过手动画圈来修复它,但这似乎很不优雅。
干杯
附上脚本的绘图部分:
ax1 = plt.subplot(gs[x,y], projection="polar")
ax1.set_theta_zero_location('N')
ax1.set_theta_direction(-1)
ax1.set_rmin(0.5)
ax1.set_rscale('log')
im=ax1.pcolormesh(theta,r,dataMasked.T, vmin = 0.5, vmax = vmax_,cmap='spectral')
im.cmap.set_bad('w',1.)
ax1.set_yticks(range(0, 90, 15))
ax1.yaxis.grid(True)
您应该在 设置 ax1.set_rscale('log')
之后设置 ax1.set_rmin(0.5)
。您可能还需要将 ax1.set_rmax()
设置为适当的值。
编辑:
看来你需要先设置rscale = log
,然后设置rmax
,再设置rmin
,否则不行:
In [1]: import matplotlib.pyplot as plt
In [2]: ax1 = plt.subplot(111, projection="polar")
In [3]: ax1.get_rmin(), ax1.get_rmax()
Out[3]: (0.0, 1.0) # Looks ok
In [4]: ax1.set_rmin(0.5)
In [5]: ax1.get_rmin(), ax1.get_rmax()
Out[5]: (0.5, 1.0) # Looks ok
In [6]: ax1.set_rscale('log')
In [7]: ax1.get_rmin(), ax1.get_rmax()
# Setting rscale=log changes both rmin and rmax
Out[7]: (9.9999999999999995e-08, 1.0000000000000001e-05)
In [8]: ax1.set_rmin(0.5)
In [9]: ax1.get_rmin(), ax1.get_rmax()
# OK, so that didn't work, because we were trying to
# set rmin to a value greater than rmax
Out[9]: (1.0000000000000001e-05, 0.5)
# Set both rmax and rmin (rmax first)
In [10]: ax1.set_rmax(1); ax1.set_rmin(0.5)
In [11]: ax1.get_rmin(), ax1.get_rmax()
Out[11]: (0.5, 1.0) # Success!