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

时间:2017-12-06 15:25:35

标签: python matplotlib polar-coordinates

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

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

但它似乎没有任何改变。

我尝试使用pyplot.gca().set_rticks([...]),但这需要提前知道滴答声,而我只想设置它们的最大数量。

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

1 个答案:

答案 0 :(得分:1)

您确实可以使用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()

enter image description here