2013-10-28 86 views
1

我在OS X上并使用Encopy(由Enthought inc。编写)来编写我的python程序。我把它从here下面的代码只生成一个点,然后它终止:Matplotlib交互式环境不起作用

from pylab import * 
import time 
t = linspace(0.0, pi, 100) 
x = cos(t) 
y = sin(t) 

ion() # turn on interactive mode 
figure(0) 
subplot(111, autoscale_on=False, xlim=(-1.2, 1.2), ylim=(-.2, 1.2)) 

point = plot([x[0]], [y[0]], marker='o', mfc='r', ms=3) 

for j in arange(len(t)): 
    # reset x/y-data of point 
    setp(point[0], data=(x[j], y[j])) 
    time.sleep(0.05) 
    draw() # redraw current figure 

ioff() # turn off interactive mode 
show() 

任何想法可能是什么问题? 下面是我得到的结果的照片。 enter image description here

+2

使用'plt.pause'取代'sleep' – tacaswell

+0

@tcaswell,谢谢。但还是单点! – Cupitor

回答

2

它只绘制一点,因为你只是告诉它绘制一个点。如果你想划清界线高达j使用以下命令:

from pylab import * 

t = linspace(0.0, pi, 100) 
x = cos(t) 
y = sin(t) 
figure(0) 
subplot(111, autoscale_on=False, xlim=(-1.2, 1.2), ylim=(-.2, 1.2)) 

point, = plot([x[0]], [y[0]], marker='o', mfc='r', ms=3) 

for j in arange(len(t)): 
    # reset x/y-data of point 
    point.set_data(x[:j], y[:j]) 
    plt.pause(0.05) 
    plt.draw() # redraw current figure 
+0

非常感谢,但你改变了什么导致了差异?我不太明白! – Cupitor

+0

@Naji我建议你手工浏览代码并查看每个函数的功能。 – tacaswell

+0

我能看到的是你改变了point.set_data参数。那么根据matplotlib的教程,setp用于设置行属性,我没有看到任何错误的代码。另外你的代码还有一个有趣的地方,你甚至不会改变交互模式。怎么来的?? – Cupitor