[英]Adding axes to polar plot with matplotlib
I know it should be as simple as hell, but actually I can't figure out how to add an additional axis (let's say at 22.5°) on a polar graph. 我知道它应该像地狱一样简单,但是实际上我无法弄清楚如何在极坐标图上添加附加轴(假设为22.5°)。 What I actually have is
我实际上拥有的是
, while I would like to obtain something like
,而我想获得类似
(obviously not in red, is just to emphasize).
(显然不是红色,只是为了强调)。
Here is part of the code I'm using: 这是我正在使用的部分代码:
ax = plt.subplot(111, projection='polar')
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
r = np.array(...)
t = []
theta = np.array(...)
ax.plot(theta, r)
max_value = np.amax(out)
ax.set_rmax(max_value)
ax.set_rticks([int(max_value/5), int(max_value*2/5),int(max_value*3/5), int(max_value*4/5)])
# ax.set_rlabel_position(-22.5)
ax.grid(True)
Thanks in advance for your support! 预先感谢您的支持!
You can use set_thetagrids
see the definition at https://matplotlib.org/api/projections_api.html 您可以使用
set_thetagrids
参见https://matplotlib.org/api/projections_api.html上的定义
in your case 在你的情况下
ax = plt.subplot(111, projection='polar')
ax.set_theta_zero_location("N")
ax.set_theta_direction(-1)
r = np.array([33, 22,50,15])
t = []
theta = np.array([33, 22,50,15])
ax.plot(theta, r)
max_value = np.amax(r)
ax.set_rmax(max_value)
ax.set_rticks([int(max_value / 5), int(max_value * 2 / 5), int(max_value * 3 / 5), int(max_value * 4 / 5)])
ax.set_thetagrids(np.arange(0, 360, 22.5))
# ax.set_rlabel_position(-22.5)
ax.grid(True)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.