[英]Matplotlib interactive environment does not work
我在OS X上并使用Encopy(由Enthought公司提供)编写我的python程序。 我从此处获取的以下代码仅生成一个点,然后终止:
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()
任何想法可能是什么问题? 下面是我得到的结果的照片。
它仅绘制一个点,因为您只告诉它绘制一个点。 如果要画线到 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.