简体   繁体   中英

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. 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

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()

结果图片

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM