【问题标题】:Is there a way to specify the axis unit on the angular axis in a pyplot polar plot?有没有办法在 pyplot 极坐标图中指定角轴上的轴单位?
【发布时间】:2017-05-12 03:58:21
【问题描述】:

现在,我的极坐标图如下所示:

但我需要它们看起来像这样:

有没有办法在pyplot 中为角轴和径向轴指定主要和次要单位?我想使用matplotlib,但由于安装freetype 很麻烦,而且我必须让IT 参与进来,我想看看我是否可以使用pyplotfirst。

谢谢

【问题讨论】:

    标签: python python-2.7 matplotlib plot


    【解决方案1】:

    我使用了this example 并添加了来自this question 的一些行。希望这符合您的需求:

    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)
    
    ax.set_title("A line plot on a polar axis", va='bottom')
    
    # angle axis
    major_ticks = np.linspace(0, 2*np.pi, 36, endpoint=False)
    minor_ticks = np.linspace(0, 2*np.pi, 360, endpoint=False)
    
    ax.set_xticks(major_ticks, minor=False)
    ax.set_xticks(minor_ticks, minor=True)
    
    # ls for linestyle, lw for linewidth
    ax.xaxis.grid(True, ls='-', lw=2, which='major')
    ax.xaxis.grid(True, which='minor')
    
    
    # radial axis
    # angle axis
    major_ticks = np.linspace(0, 2, 4, endpoint=False)
    minor_ticks = np.linspace(0, 2, 40, endpoint=False)
    
    ax.set_yticks(major_ticks, minor=False)
    ax.set_yticks(minor_ticks, minor=True)
    
    # ls for linestyle, lw for linewidth
    ax.yaxis.grid(True, ls='-', lw=2, which='major')
    ax.yaxis.grid(True, which='minor')
    
    plt.show()
    

    这给出了以下图片[您可能需要调整一些细节;-)]:

    【讨论】:

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