如何在Python中可视化torch_geometric图?

问题描述 投票:0回答:2

让我们考虑一个例子,我有以下坐标格式的邻接矩阵:

> edge_index.numpy() = array([[    0,     1,     0,   3,   2],
                              [    1,     0,     3,   2,   1]], dtype=int64)

这意味着节点 0 链接到节点 1,反之亦然,节点 0 链接到 3 等等...

你知道如何用 nx.draw() 来绘制这个图吗?

谢谢你。

graph pytorch draw
2个回答
18
投票
import networkx as nx

edge_index = torch.tensor([[0, 1, 1, 2],
                           [1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)

data = torch_geometric.data.Data(x=x, edge_index=edge_index)
g = torch_geometric.utils.to_networkx(data, to_undirected=True)
nx.draw(g)

0
投票

是否需要添加 plt.show() 来查看绘图?

© www.soinside.com 2019 - 2024. All rights reserved.