如何减少或以其他方式影响极坐标图中径向刻度的数量?

How can I reduce or otherwise influence the number of radial ticks in a polar plot?

我想要一个极坐标图,但要减少径向(r 维度)刻度的数量。我已经尝试了其他问题的建议解决方案,例如

pyplot.locator_params(axis='y', nticks=6)

但似乎没有任何改变。

我尝试使用 pyplot.gca().set_rticks([...]),但这需要提前知道报价,而我只想设置报价的最大值。

为了减少刻度(或圆圈)的数量,我还能尝试什么?

您确实可以使用 ax.set_rticks() 来指定您想要的特定刻度标签,例如

ax.set_rticks([0.5, 1, 1.5, 2])

his example on the matplotlib page所示。

在某些情况下,这可能是不希望的,通常的定位器参数会更可取。您可以通过ax.yaxis.get_major_locator().base获取定位器并通过.set_params()设置参数。这里要改nbins参数,

ax.yaxis.get_major_locator().base.set_params(nbins=3)

完整示例:

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.yaxis.get_major_locator().base.set_params(nbins=3)

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