graph4ai / graph4nlp

Graph4nlp is the library for the easy use of Graph Neural Networks for NLP. Welcome to visit our DLG4NLP website (https://dlg4nlp.github.io/index.html) for various learning resources!
Apache License 2.0
1.67k stars 201 forks source link

Is there a way to visualize the GraphData? #547

Closed nashid closed 2 years ago

nashid commented 2 years ago

❓ Questions and Help

I am wondering whether is there a way to visualize the GraphData object?

Currently, I am doing the following:

import networkx as nx
import dgl
import matplotlib.pyplot as plt
from networkx.drawing.nx_pydot import write_dot

graph_data is a GraphData object.

graph_dgl = graph_data.to_dgl()
graph_nx = dgl.to_networkx(graph_dgl)
nx.draw(graph_nx, width=0.03, with_labels=True)
plt.show()
plt.savefig('foo.pdf')
write_dot(graph_nx, "foo.dot")

This is how I am visualizing the GraphData object. But DGL does not preserve the "text", i.e. tokens in the node. So I am wondering is there some other API that I can use to visualize the GraphData object with the "token" values itself.

Any pointers welcome.

SaizhuoWang commented 2 years ago

Currently GraphData does not support the feature of visualization. You may convert it to another type (e.g. networkx.Graph) for visualization.