2013-10-19 63 views
1

我不能为我的生活得到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

回答

1

以上 - 无需在取消干啥,正常工作与刚:

ipython animate.py 

因此,没有

ipython --pylab=auto 

In [1]: import animate 

所以我觉得你的问题是你试图将后台选择很重要的交互模式和一个连续不间断运行的脚本结合起来 - 这是一个冲突。

阅读文档herehere我怀疑你需要拨打IPython.lib.inputhook.InputHookManageranimate.py来设置你的后端。

IPython的0.13.2 matplotlib '1.3.0' 的Kubuntu 13.10

+0

您好Steve,如果您不使用-pylab开关,那么它不会激活我感兴趣使用的ipython后端(反正afaik) – jeremy

0

我也一直在努力这一点。似乎大多数用户使用Jake Vanderplaas的JSAnimation。链接。 https://github.com/jakevdp/JSAnimation。然而,这不是Enthought发行版中的一个包,因此需要单独导入。