我在OS X上并使用Encopy(由Enthought公司提供)编写我的python程序。我从here那里获取的以下代码仅生成一个点,然后终止:
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
关于python - Matplotlib交互式环境不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19642052/