我有一个绘制了一系列圆形的图表,但是,由于轴的原因,它们不是圆形,而是椭圆形,如下图所示。我知道这是一个反复出现的问题,并且有很多这样的问题......但是我找不到任何可以帮助我的东西!我尝试放入 fig = plt.figure(0, Figsize=(14.5, 1.75))
这确实有一点帮助,但也许 ax.set_aspect()
但是,使用标量对此也没有多大帮助!
对于该图,标记为 *** 的线不存在
我的代码如下:
fig = plt.figure(0)
ax = fig.add_subplot(111)
ax.set_aspect(???)#*** not sure if this should be here or not
plt.axis([-5, 20, -1, 1])
circle1 = plt.Circle((-1,0.25), radius=0.2, color='c')
circle2= plt.Circle((4,-0.5), radius=0.5, color='m')
plt.gcf().gca().add_artist(circle1)
plt.gcf().gca().add_artist(circle2)
最佳答案
您可以将宽高比设置为相等
,但您还需要为两个轴选择相似的尺寸,如下所示:
from matplotlib import pyplot as plt
fig = plt.figure(0)
ax = fig.add_subplot(111)
ax.set_aspect('equal')
plt.axis([-5, 5, -5, 5])
circle1 = plt.Circle((-1, 0.25), radius=0.2, color='c')
circle2 = plt.Circle((4, -0.5), radius=0.5, color='m')
ax.add_artist(circle1)
ax.add_artist(circle2)
plt.show()
关于python - 圆形变成椭圆形 - 在 Python 中设置长宽比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33898598/