【问题标题】:How do you reverse the axis and set the zero position for a polar plot in Matplotlib?如何在 Matplotlib 中反转轴并设置极坐标图的零位?
【发布时间】:2018-04-13 20:23:48
【问题描述】:

使用 Matplotlib 的极坐标图时,theta 轴的默认零位是或向右,角度逆时针增加,如this example 所示。

如何指定零位并反转增加theta的方向?在撰写本文时,documentation 相对有限。

【问题讨论】:

    标签: python matplotlib polar-coordinates


    【解决方案1】:

    轴方法set_theta_zero_locationset_theta_direction 允许您分别指定零位置和增加theta 的方向。这是Matplotlib example的修改版本。

    import numpy as np
    import matplotlib.pyplot as plt
    
    r = np.arange(0, 2, 0.01)
    theta = 2 * np.pi * r
    
    ax = plt.subplot(111, projection='polar')
    ax.plot(theta, r)
    ax.set_rmax(2)
    ax.set_rticks([0.5, 1, 1.5, 2])  # less radial ticks
    ax.set_rlabel_position(-22.5)  # get radial labels away from plotted line
    ax.grid(True)
    
    # ---- mod here ---- #
    ax.set_theta_zero_location("N")  # theta=0 at the top
    ax.set_theta_direction(-1)  # theta increasing clockwise
    # ---- mod here ---- #
    
    ax.set_title("A line plot on a polar axis", va='bottom')
    plt.show()
    

    请注意,对于 quiverplot,这些方法当前会生成 strange results (see GitHub issue)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-13
      • 2019-08-25
      • 1970-01-01
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多