【问题标题】:Move radial tick labels on a polar plot in matplotlib在 matplotlib 的极坐标图上移动径向刻度标签
【发布时间】:2015-04-01 15:14:36
【问题描述】:

来自matplotlib examples

import numpy as np
import seaborn as sbs
import matplotlib.pyplot as plt

r = np.arange(0, 3.0, 0.01)
theta = 2 * np.pi * r

ax = plt.subplot(111, polar=True)
ax.plot(theta, r, color='r', linewidth=3)
ax.set_rmax(2.0)
ax.grid(True)

ax.set_title("A line plot on a polar axis", va='bottom')
plt.show()

如何将径向刻度标签(0.5、1.0、1.5、2.0)移动到不同的角度,比如 120 度?

【问题讨论】:

    标签: python matplotlib polar-coordinates


    【解决方案1】:

    对于 1.4 或更高版本,您可以使用“set_rlabel_position”。例如将径向刻度放置在一条长线上,例如 135 度:

    ax.set_rlabel_position(135)
    

    相关文档位于here,有点隐藏在“projections”下。

    在产量上方添加一行(我没有 seaborn,所以它具有默认的 matplotlib 格式):

    在 1.4 之前,ax.set_rgrids 可以接受角度参数。

    【讨论】:

      【解决方案2】:

      我尝试使用@alkamid 回答中的编辑运行示例代码,但最终以错误结束

      AttributeError: 'PolarAxesSubplot' object has no attribute 'set_rlabel_position'
      

      我的 matplotlib 版本是 1.3.1。但是我通过以下代码行找到了这个答案python matplolib polar chart x-axis label position

      ax.set_rgrids([5,10], angle=22)
      

      这对我有用并产生了想要的输出。

      【讨论】:

        猜你喜欢
        • 2013-06-14
        • 2019-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-22
        • 1970-01-01
        相关资源
        最近更新 更多