MovieWriter imagemagick不可用

时间:2019-04-27 18:31:10

标签: python python-3.x jupyter-notebook imagemagick python-visual

我正在尝试对图形进行动画处理,但是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)

期望:动画应该可以正常工作,并且能够显示更新的颜色

1 个答案:

答案 0 :(得分:1)

如下所示,它在安装networkx软件包并添加pillowwritter后可以正常工作。

import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from matplotlib.animation import FuncAnimation, PillowWriter 

networkx