我不能为我的生活得到iPython显示一个动画的情节。此代码直接从matplotlib动画示例中获取,并且使用普通的旧python(又名python animate.py
)可以正常工作。iPython + pylab/matplotlib动画挂
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
line, = ax.plot(np.random.rand(10))
ax.set_ylim(0, 1)
def update(data):
line.set_ydata(data)
return line,
def data_gen():
while True: yield np.random.rand(10)
ani = animation.FuncAnimation(fig, update, data_gen, interval=100)
#plt.ion()
plt.show()
#while 1:
#plt.draw()
与ipython --pylab auto animate.py
打电话,ipython --pylab tk animate.py
都导致窗口立即消失。如果我取消注释ion()
和plt.draw()
它只画一个框架,然后挂起。我需要使用iPython,因为它比普通的matplotlib实现更加线程安全。
我在做什么错?在OSX 10.8使用python2.7.2与IPython的1.1和1.3 matplotlib
您好Steve,如果您不使用-pylab开关,那么它不会激活我感兴趣使用的ipython后端(反正afaik) – jeremy