【发布时间】:2017-08-21 23:12:39
【问题描述】:
我正在尝试制作随时间变化的 networkx 图的动画。我正在使用 networkx_draw 实用程序来创建图表的 matplotlib 图形,并使用 matplotlib 的 ArtistAnimation 模块从艺术家 networkx 制作的动画中创建动画。我已经对我在这里所做的事情进行了最低限度的复制:
import numpy as np
import networkx as nx
import matplotlib.animation as animation
import matplotlib.pyplot as plt
# Instantiate the graph model
G = nx.Graph()
G.add_edge(1, 2)
# Keep track of highest node ID
G.maxNode = 2
fig = plt.figure()
nx.draw(G)
ims = []
for timeStep in xrange(10):
G.add_edge(G.maxNode,G.maxNode+1)
G.maxNode += 1
pos = nx.drawing.spring_layout(G)
nodes = nx.drawing.draw_networkx_nodes(G, pos)
lines = nx.drawing.draw_networkx_edges(G, pos)
ims.append((nodes,lines,))
plt.pause(.2)
plt.cla()
im_ani = animation.ArtistAnimation(fig, ims, interval=200, repeat_delay=3000,blit=True)
im_ani.save('im.mp4', metadata={'artist':'Guido'})
该过程在实时显示数字时运行良好,它会产生我想要的动画。它甚至在脚本末尾的图形中生成循环动画,这也是我想要的,这表明动画过程有效。但是,当我打开保存到磁盘的“im.mp4”文件时,它是一个空白的白色图像,运行了预期的时间,从不显示任何实时显示的图形图像。
我使用的是 networkx 1.11 版和 matplotlib 2.0 版。我正在使用 ffmpeg 制作动画,并且在 Mac、OSX 10.12.3 上运行。
我做错了什么?
【问题讨论】:
标签: python animation matplotlib ffmpeg networkx