在 matplotlib 中的极坐标图上移动径向刻度标签

Move radial tick labels on a polar plot in matplotlib

来自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 度?

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

ax.set_rlabel_position(135)

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

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

在 1.4 之前,ax.set_rgrids 可以使用角度参数。

我尝试 运行 使用 @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)

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