我正在尝试为图表设置动画,但 jupyter 给出了错误:
MovieWriter imagemagick 不可用。并且只是为第一张图像制作动画(这很明显,因为 MovieWriter 不起作用)。如何解决?
Python版本:3
这是代码
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from matplotlib.animation import FuncAnimation
# number of nodes
size = 10
# generate graph
G=nx.complete_graph(size)
frame = np.random.randint(0, 5, (size, size)) # random ndarray between 0 and 5, length and number of frames = number of nodes in the graph
pos = nx.spring_layout(G)
nodes = nx.draw_networkx_nodes(G,pos)
edges = nx.draw_networkx_edges(G,pos)
plt.axis('off')
def update(i):
nc = frame[i] # np.random.randint(2, size=200)
nodes.set_array(nc)
return nodes,
# output animation; its important I save it
fig = plt.gcf()
ani = FuncAnimation(fig, update, interval=50, frames=range(size), blit=True)
ani.save('crap.gif', writer='imagemagick', savefig_kwargs={'facecolor':'white'}, fps=1)
期望:动画应该可以工作并且能够显示更新的颜色