Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

Can NetworkX handle large graphs?

NX is certainly capable of handling graphs that large, however, performance will largely be a function of your hardware setup. Aric will likely give a better answer, but NX loads graphs into memory at once, so in the ranges your are describing you will need a substantial amount of free memory for it to work.

Is NetworkX scalable?

The fact that networkX is mostly written in python does not mean that it is not scalable, nor claims perfection. There is always a trade-off. If you throw more money on your "machines", you'll have as much scalability as you want plus the benefits of using a pythonic graph library.

What is Nbunch in NetworkX?

nbunch. An nbunch is a single node, container of nodes or None (representing all nodes). It can be a list, set, graph, etc..


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

Since it seems that your network layout is too "messy", you might want to try different graph layout algorithms and see which one suits you best.

nx.draw(G)  
nx.draw_random(G)  
nx.draw_circular(G)  
nx.draw_spectral(G)  
nx.draw_spring(G)  

Also, if you have too many nodes (let's say some thousands) visualizing your graph can be a problem.