2015-11-24 37 views
1

但是,由于它们不是以圆形出现的轴,而是以椭圆形形式绘制,因此您可以在图像中看到它下面。我知道这是一个反复出现的问题,并且有很多这样的问题......但是我找不到任何帮助我的东西!我试过放入fig = plt.figure(0, figsize=(14.5, 1.75))这对你有一点帮助,但也许ax.set_aspect()然而,使用标量对此也没有太大的帮助!以椭圆形出现的圆 - 在Python中设置纵横比

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) 

回答

1

您可以设置方面是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

+0

但是,我使用圆的数据(第4列代表y轴的值)。那么有没有办法做到这一点,保持同一个轴? – lyche

+0

您可以使用任何您需要的轴,使用'equal'将使圆形保持圆形,但最终会形成一个矩形图。 –

+0

好吧,那么这些可能出现的圆圈的唯一方法是让它们写成椭圆形?谢谢你的帮助 – lyche