简体   繁体   中英

Polar plot in Matplotlib not centered

For some reasons, when I try to plot (theta = 0, r = 0) using the following code :

import matplotlib.pyplot as plt

plt.polar(0, 0, marker='x')
plt.show()

The point is not centered :

带中心的极坐标图

I was able to reproduce this error multiple times on my computer and on Repl.it : Link

So, how can I center the polar plot, so that the x shows in the center of it ?

It's "centered", but the radius starts at a negative value, something around -0.04 in your case. Try setting rmin after you have plotted your point:

import matplotlib.pyplot as plt

ax = plt.subplot(111, projection='polar')
ax.plot([0], [0], marker = 'x')
ax.set_rmax(5)
ax.set_rmin(0)
plt.show()

This gives a single little x exactly in the middle of the circle with radius 5 .

The problem usually does not appear if you plot multiple points with many interesting values, because it then sets the radius range to more sane defaults.

This is not a bug, you just have to set the limit of the r axis :

ax.set_rlim(0,2)

This gives the correct result

在此处输入图片说明

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