How can I specify an exact output size for my networkx graph?

user428370 picture user428370 · Aug 25, 2010 · Viewed 36k times · Source

http://imgur.com/7wiRw.png

The above is the output of my current graph. However, I have yet to manage what I am trying to achieve. I need to output my graph in a larger size so that each node/edge can be viewed with ease.

I've tried nx.draw(G, node_size=size), but that only increases the size of the nodes, not the distance between nodes and edges.

Answer

Aric picture Aric · Dec 5, 2011

You could try either smaller nodes/fonts or larger canvas. Here is a way to do both:

import matplotlib.pyplot as plt
import networkx as nx
G = nx.cycle_graph(80)
pos = nx.circular_layout(G)
# default
plt.figure(1)
nx.draw(G,pos)
# smaller nodes and fonts
plt.figure(2)
nx.draw(G,pos,node_size=60,font_size=8) 
# larger figure size
plt.figure(3,figsize=(12,12)) 
nx.draw(G,pos)
plt.show()