Spyder / Python:尝试制作动画,但没有数据出现

时间:2019-02-21 04:21:37

标签: python numpy matplotlib animation spyder

我正在Windows 7下使用Anaconda和Spyder运行matplotlib。我画了各种图。现在,我正在尝试制作动画。我已经从matplotlib演示源代码网站复制了大约五个动画演示,因此毫无疑问,该代码是正确的。通常会发生的是显示轴但没有数据。一旦我显示了线框图,但它没有移动。

大约一个月前,我从其网站下载了Anaconda,所以大概我拥有的是最新版本。我在堆栈溢出中发现了有关类似问题的问题,但没有答案。看起来很冷酷。我想唯一的答案是购买另一台运行不同操作系统的计算机。但是我想问一下。

我尝试了

import matplotlib
matplotlib.use('TkAgg')

没有区别。

numpy version is 1.15.4
python version is 3.7
spyder version is 3.3.2

来自https://matplotlib.org/examples/animation/basic_example.html的代码

“”“

简单的动画示例

此示例包含两个动画。第一个是随机游动图。的 第二个是图像动画。

“”“

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation


def update_line(num, data, line):
    line.set_data(data[..., :num])
    return line,

fig1 = plt.figure()

data = np.random.rand(2, 25)
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
                                   interval=50, blit=True)

# To save the animation, use the command: line_ani.save('lines.mp4')

fig2 = plt.figure()

x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)
ims = []
for add in np.arange(15):
    ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),))

im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
                                   blit=True)
# To save this second animation with some metadata, use the following command:
# im_ani.save('im.mp4', metadata={'artist':'Guido'})

plt.show()

0 个答案:

没有答案