简体   繁体   English

如何使用任何工具可视化 HeteroData pytorch 几何图形?

[英]How to visualize HeteroData pytorch geometric graph with any tool?

Hello what is a good way to visualize a pyg HeteroData object?您好,什么是可视化 pyg HeteroData object 的好方法? (defined similarly: https://pytorch-geometric.readthedocs.io/en/latest/notes/heterogeneous.html#creating-heterogeneous-gnns ) (定义类似: https://pytorch-geometric.readthedocs.io/en/latest/notes/heterogeneous.html#creating-heterogeneous-gnns

I tried with.networkx but I think it is restricted to homogeneous graph ( it is possible to convert it but it is much less informative).我试过 with.networkx 但我认为它仅限于同构图(可以转换它但信息量少得多)。

g = torch_geometric.utils.to_networkx(data.to_homogeneous(), to_undirected=False )

Did anyone try to do it with other python lib (matplotlib) or js (sigma.js/d3.js)?有没有人尝试用其他 python lib(matplotlib)或 js(sigma.js/d3.js)来做?

Any docs link you can share?您可以共享任何文档链接吗?

I have done the following:我做了以下事情:

import networkx as nx
from matplotlib import pyplot as plt
from torch_geometric.nn import to_hetero

g = torch_geometric.utils.to_networkx(data.to_homogeneous())
# Networkx seems to create extra nodes from our heterogeneous graph, so I remove them
isolated_nodes = [node for node in g.nodes() if g.out_degree(node) == 0]
[g.remove_node(i_n) for i_n in isolated_nodes]
# Plot the graph
nx.draw(g, with_labels=True)
plt.show()

在此处输入图像描述

However, it's true that it was "flattened" to a homogeneous, while it'd be more interesting to, for example, use different colors for different types of nodes.然而,它确实被“扁平化”为同质的,而更有趣的是,例如,对不同类型的节点使用不同的 colors。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM