Python 如何为我的 networkx 图指定确切的输出大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3567018/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I specify an exact output size for my networkx graph?
提问by


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.
我试过nx.draw(G, node_size=size),但这只会增加节点的大小,而不是节点和边之间的距离。
回答by thetarro
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.
另外,如果你有太多的节点(比如几千个),可视化你的图表可能是一个问题。
回答by Aric
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()

