在Python中,以椭圆形式出现的圆设置了纵横比

2024-05-26 11:09:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个图,它画了一系列的圆,但是,因为轴不是圆的,而是椭圆的,如下图所示。我知道这是一个反复出现的问题,还有很多类似的问题。。。但是我找不到任何对我有帮助的东西!我试着加入fig = plt.figure(0, figsize=(14.5, 1.75))这有点帮助,但是也许{}但是,使用标量也没有太大帮助!在

enter image description here

对于这个地块,标有***的线不在那里

我的代码如下:

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)

Tags: addartistfignotpltaxgcfcolor
1条回答
网友
1楼 · 发布于 2024-05-26 11:09:41

您可以将纵横比设置为equal,但还需要为两个轴选择相似的大小,如下所示:

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

显示如下: enter image description here

相关问题 更多 >