Reputation: 485
The following snippet comes from the tutorial https://cnvrg.io/graph-neural-networks/. How can I visualize a graph from the dataset
? Using something like matplotlib
if possible.
import dgl
import torch
import torch.nn as nn
import torch.nn.functional as F
import dgl.data
dataset = dgl.data.CoraGraphDataset()
g = dataset[0]
Upvotes: 2
Views: 5397
Reputation: 540
import dgl.data
import matplotlib.pyplot as plt
import networkx as nx
dataset = dgl.data.CoraGraphDataset()
g = dataset[0]
options = {
'node_color': 'black',
'node_size': 20,
'width': 1,
}
G = dgl.to_networkx(g)
plt.figure(figsize=[15,7])
nx.draw(G, **options)
It is a huge graph so you might have to play with the sizes (node, width, figure, etc.). Here are some useful links:
Upvotes: 6