6

Hello what is a good way to visualize a pyg HeteroData object ? (defined similarly: 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).

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)?

Any docs link you can share?

partizanos
  • 1,064
  • 12
  • 22

1 Answers1

-1

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()

enter image description here

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.

Laurent
  • 1,914
  • 2
  • 11
  • 25
  • This is a homogeneous visualization i.e. no visual distinction but thanks it may be useful for someone else – partizanos May 25 '23 at 16:47
  • That's what I emphasized in my answer "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." – Laurent Jun 05 '23 at 13:19
  • Hello yes but the question is about heteroData. – partizanos Jun 06 '23 at 14:14