iPython+pylab/matplotlib动画挂起

2024-04-25 22:27:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我一辈子都不能让伊普顿演动画片。这段代码直接取自matplotlib动画示例,使用普通的python(akapython animate.py)可以很好地工作。在

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实现更安全。在

我做错什么了?在带有iPython 1.1和matplotlib 1.3的osx10.8上使用python2.7.2


Tags: pyimportdatamatplotlibasnplinefig
2条回答

我也试过这个。似乎大多数用户都使用Jake Vanderplaas的JSAnimation。链接。https://github.com/jakevdp/JSAnimation。然而,这并不是热情发行版中的一个软件包,因此需要单独进口。在

以上-无需取消注释anythin,只需:

ipython animate.py

是的

^{pr2}$

所以我认为你的问题是你试图将交互模式与一个没有交互的连续运行的脚本相结合,这是一个冲突。在

阅读文档here和{a2}我怀疑您需要调用animate.py中的IPython.lib.inputhook.InputHookManager来设置后端。在

IPython 0.13.2 matplotlib'1.3.0'kubuntu 13.10

相关问题 更多 >