matplotlib set_rmax和set_rticks无法正常工作

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

我在anaconda jupyter笔记本中使用python3,并在极坐标中绘制图形。我希望所有的图形具有相同的rmax和rticks,但是当我设置它们时,它们不会被应用并且点不能正确绘制。这是我的代码,没有,然后与他们。

%pylab inline
X = asarray([[0.23, 0.73],[0.22, 1.16],[0.18, 1.86],[0.17, 2.39],[0.24, 2.74],[0.16, 3.43],[0.16, 3.87],[0.13, 4.39],[0.14, 5.00],[0.17, 5.53]])

ax0 = subplot(111, projection='polar')
ax0.plot(X[:,1], X[:,0], 'r+')
show()

ax1 = subplot(111, projection='polar')
ax1.set_rmax(0.8)
ax1.set_rticks([0.2, 0.4, 0.6, 0.8])
ax1.plot(X[:,1], X[:,0], 'r+')
show()

这是情节。

enter image description here enter image description here

python matplotlib ipython polar-coordinates
1个回答
2
投票

问题是你首先设置rmax,然后绘制你的极坐标图。因此,一旦绘制,限制将自动调整,并且您的设置rmaxrticks将被覆盖。

解决方案是首先绘制,然后设置rmaxrticks,如下所示。

ax1 = plt.subplot(111, projection='polar')
ax1.plot(X[:,1], X[:,0], 'r+')
ax1.set_rmax(0.8)
ax1.set_rticks([0.2, 0.4, 0.6, 0.8])

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.