如何删除极坐标图中的最后一个刻度

问题描述 投票:0回答:1

我想删除极坐标图中的最后一个刻度。我找到了一种用于非极坐标图here的方法,它说:

yticks[-1].set_visible(False)

其结果是:

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

我试图写rticks而不是yticks,但这产生了相同的错误。我在下面拍了一张图片:

enter image description here

pi标签来自here

python matplotlib axes polar-coordinates
1个回答
0
投票

我不知道您是如何制作情节的,但这似乎可行:

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)  # Move radial labels away from plotted line
ax.grid(True)

ax.set_title("A line plot on a polar axis", va='bottom')
tick_pos= [0, np.pi/2, np.pi, 3*np.pi/2]
labels = ['0', '$\pi/2$', '$\pi$', '$3\pi/2$']
plt.xticks(tick_pos, labels)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.