【问题标题】:iPython + pylab/matplotlib animations hangiPython + pylab/matplotlib 动画挂起
【发布时间】:2013-10-19 13:56:30
【问题描述】:

我一辈子都无法让 iPython 显示动画情节。此代码直接取自 matplotlib 动画示例,使用普通的旧 python(又名python 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.pyipython --pylab tk animate.py 调用都会导致窗口立即消失。如果我取消注释 ion()plt.draw() 它只会绘制一个帧然后挂起。我需要使用 iPython,因为它比普通的 matplotlib 实现更加线程安全。

我做错了什么?在 osx 10.8 上使用 python2.7.2 和 iPython 1.1 和 matplotlib 1.3

【问题讨论】:

    标签: python animation matplotlib ipython


    【解决方案1】:

    以上 - 无需取消注释任何内容都可以正常工作:

    ipython animate.py
    

    也是这样

    ipython --pylab=auto
    
    In [1]: import animate
    

    所以我认为您的问题是您正在尝试将后端选择很重要的交互模式与连续运行而没有交互的脚本结合起来 - 这是一个冲突。

    阅读文档herehere 我怀疑您需要调用animate.py 中的IPython.lib.inputhook.InputHookManager 来设置您的后端。

    IPython 0.13.2 matplotlib '1.3.0' kubuntu 13.10

    【讨论】:

    • 嗨,史蒂夫,如果您不使用 --pylab 开关,那么它不会激活我有兴趣使用的 ipython 后端(无论如何都是 afaik)
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-28
      • 2014-10-09
      • 1970-01-01
      • 2014-02-24
      相关资源
      最近更新 更多