我正在制作网络图动画,并希望通过节点的大小显示与节点相关的数据。颜色而不是节点大小的等效动画:
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
G = nx.ladder_graph(4)
fig = plt.figure(figsize=(8,8))
pos = nx.spring_layout(G)
nc = np.random.random(len(G))
nodes = nx.draw_networkx_nodes(G,pos,node_color=nc)
edges = nx.draw_networkx_edges(G,pos)
def update(n):
nc = np.random.random(len(G))
nodes.set_array(nc)
return nodes,
anim = FuncAnimation(fig, update, interval=20, blit=True)
并且可以生成一个具有数据给定的节点大小的静态帧
nodes = nx.draw_networkx_nodes(G,pos,node_size=400*nc)
我知道对于大小特征没有相当于 .set_array 的东西,那么最好的方法是什么?
最佳答案
等效的是self._size
属性。在新版本的 mpl (1.4.0rc1 + ) 中,有一个
PathCollection
上的 set_sizes
方法。
关于python - 在 matplotlib 散点图中对标记的大小进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25007438/