2013-03-14 95 views
0

我想在matplotlib绘制一个椭圆,但是当我执行此代码:为什么我的椭圆不出现?

from matplotlib.pyplot import * 
from matplotlib.patches import Ellipse 

fig = Figure() 
ax = fig.add_subplot(111) 
ax.add_artist(Ellipse(xy=(1, 1), width=2, height=2, facecolor='g', edgecolor='k', alpha=.1)) 
show() 

没有任何反应都没有。我没有数字,更不是椭圆。

什么给?

非常感谢!

回答

2

figure必须拼写成小写。你想create a figure并显示它。如果使用大写拼写,则实例化Figure class

from matplotlib import pyplot as plt 
from matplotlib.patches import Ellipse 

fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.add_artist(Ellipse(xy=(1, 1), width=2, height=2, facecolor='g', edgecolor='k', alpha=.1)) 
plt.show() 
+0

whaaaaat?对于我迄今为止制作的每一个情节,“数字”都很好;不是一堂课吗?那么,'figure'和'figure'之间有什么区别? – blz 2013-03-14 11:54:19

+0

,即使使用'figure'的小写拼写,我的问题仍然存在,至少在交互式shell中。在ipython笔记本中,这似乎工作。 – blz 2013-03-14 11:55:07

+0

你使用什么版本的mpl和python?它适用于我的机器上的mpl 1.2和python 2.7。你使用什么后端? – 2013-03-14 11:56:18