开发者

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

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

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 no开发者_C百科des and edges.


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

import networkx as nx
import matplotlib.pyplot as plt

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.


you can increase the size of the plot as well as set the dpi. If dpi is lowered that nodes would spread out more.

G = nx.Graph()
# Add edges
fig = plt.figure(1, figsize=(200, 80), dpi=60)
nx.draw(G, with_labels=True, font_weight='normal')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜