用什么工具绘制动画网络图

Pin*_*ino 0 python graph networkx

我想获得复杂图上随机游走概率分布的动画。我目前使用 PythonNetworkX来处理图形和评估行走的动力学。

我的目标是制作一个动画(比如 GIF 文件),其中图形的每个节点的大小与其程度(或其他拓扑属性)成正比,颜色与标量属性(概率分布)成正比。节点的大小和位置在时间上保持固定,但颜色会发生变化。

目前,我可以使用Gephi在某个时刻绘制具有所需属性的图形,但我想知道如何制作动画,或者如何自动为每个时刻生成图像的过程。

有人可以指出一些已经做过类似事情的参考吗?除了 Gephi,我还可以使用不同的可视化工具。实际上,理想情况下,我希望我的所有工作流程都在 Python 中进行,而无需求助于外部程序。

Pau*_*sen 8

FuncAnimation在 matplotlib 中相当简单:

import numpy as np
import matplotlib.pyplot as plt; plt.close('all')
import networkx as nx
from matplotlib.animation import FuncAnimation

def animate_nodes(G, node_colors, pos=None, *args, **kwargs):

    # define graph layout if None given
    if pos is None:
        pos = nx.spring_layout(G)

    # draw graph
    nodes = nx.draw_networkx_nodes(G, pos, *args, **kwargs)
    edges = nx.draw_networkx_edges(G, pos, *args, **kwargs)
    plt.axis('off')

    def update(ii):
        # nodes are just markers returned by plt.scatter;
        # node color can hence be changed in the same way like marker colors
        nodes.set_array(node_colors[ii])
        return nodes,

    fig = plt.gcf()
    animation = FuncAnimation(fig, update, interval=50, frames=len(node_colors), blit=True)
    return animation

total_nodes = 10
graph = nx.complete_graph(total_nodes)
time_steps = 20
node_colors = np.random.randint(0, 100, size=(time_steps, total_nodes))

animation = animate_nodes(graph, node_colors)
animation.save('test.gif', writer='imagemagick', savefig_kwargs={'facecolor':'white'}, fps=0.5)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明