简体   繁体   English

Matplotlib中的极坐标图未居中

[英]Polar plot in Matplotlib not centered

For some reasons, when I try to plot (theta = 0, r = 0) using the following code : 由于某些原因,当我尝试使用以下代码绘制(theta = 0, r = 0)

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 我能够在计算机和Repl.it上多次重现此错误: 链接

So, how can I center the polar plot, so that the x shows in the center of it ? 那么,如何才能使极坐标图居中,以使x在其中心显示?

It's "centered", but the radius starts at a negative value, something around -0.04 in your case. 它是“居中的”,但半径从负值开始,在您的情况下约为-0.04 Try setting rmin after you have plotted your point: 绘制好点后,尝试设置rmin

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 . 这将在半径为5的圆的正中给出一个小x

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 : 这不是错误,您只需要设置r轴的限制即可:

ax.set_rlim(0,2)

This gives the correct result 这给出了正确的结果

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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