import matplotlib.animation as animation
import matplotlib.pyplot as plt
import networkx as nx
import matplotlib
matplotlib.use('TkAgg')
def draw(i):
N = 10
G = nx.random_graphs.erdos_renyi_graph(N, 0.1)
G.add_nodes_from([i for i in range(N)])
pos = nx.spring_layout(G)
ax.cla()
ax.axis('off')
ax.set_title('Epoch: %d' % i)
nx.draw_networkx(G, pos, with_labels=True, node_size=300, ax=ax)
fig = plt.figure(dpi=150)
fig.clf()
ax = fig.subplots()
draw(0) # draw the prediction of the first epoch
fps = 1
ani = animation.FuncAnimation(fig, draw, frames=10, interval=1000/fps)
ani.save('change.gif', writer='pillow', fps=fps)
plt.show()
更多内容见:
https://blog.youkuaiyun.com/u013180339/article/details/77002254