I have a very complicated graph that includes lots of nodes and edges. For better understanding, I want to visualize the graph. I worked with lots of libraries and I didn't get what I want.
This article was great, but I couldn't define the pos
attribute for my graph.
The random geometric graph has a pos
attribute by default.
number of nodes = 567
number of edges = 846
I used nx.random_layout() to define 'pos' attributes for my nodes. My graph name is taradodGraph
pos = nx.random_layout(taradodGraph)
dmin = 1
ncenter = 0
for n in pos:
x, y = pos[n]
d = (x - 0.5)**2 + (y - 0.5)**2
if d < dmin:
ncenter = n
dmin = d
# color by path length from node near center
p = dict(nx.single_source_shortest_path_length(taradodGraph, ncenter))
plt.figure(figsize=(8, 8))
nx.draw_networkx_edges(taradodGraph, pos, nodelist=[ncenter], alpha=0.4)
nx.draw_networkx_nodes(taradodGraph, pos, nodelist=list(p.keys()),
node_size=80,
node_color=list(p.values()),
cmap=plt.cm.Reds_r)
plt.xlim(-0.05, 1.05)
plt.ylim(-0.05, 1.05)
plt.axis('off')
plt.savefig('foo.png')
plt.show()