【问题标题】:Matplotlib: set_rmin not working for logarithmic polar projectionMatplotlib:set_rmin 不适用于对数极坐标投影
【发布时间】:2015-08-20 08:36:34
【问题描述】:

我正在尝试在极坐标投影中绘制网格数据。但是,我需要在 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)    

【问题讨论】:

    标签: python matplotlib logarithm polar-coordinates


    【解决方案1】:

    你应该设置ax1.set_rmin(0.5)你设置ax1.set_rscale('log')之后。您可能还需要将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 限制,但是我猜极坐标投影并不那么容易实现
    • 是的,我不知道为什么要用对数刻度将两个限制都更改为如此小的数字。好吧,至少它现在有效。请考虑接受答案,以便其他人知道您的问题已解决:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多