开发者

networkx: how to control radius of circular_layout()?

开发者 https://www.devze.com 2023-03-18 17:56 出处:网络
I\'m working with random graphs (created with nx.开发者_如何学运维gnm_random_graph()). The only neat way to lay these out is with a circular layout. Networkx provides at least two equivalent ways to d

I'm working with random graphs (created with nx.开发者_如何学运维gnm_random_graph()). The only neat way to lay these out is with a circular layout. Networkx provides at least two equivalent ways to do this but I don't know how to control the radius of the circle with either of them:

nx.draw_networkx(G, pos=nx.circular_layout(G))
nx.draw_circular(G) 

Does anybody know how to increase the radius/diameter so the nodes are not so squashed together ?

Thanks, Paul


You can get the effect of changing radius by either reducing the node (and font) size, or increasing the figure size. Here is an example showing both ways to improve a circular layout of a cycle graph with overlapping nodes.

import pylab
import networkx as nx
G=nx.cycle_graph(80)
pos=nx.circular_layout(G)
pylab.figure(1)
nx.draw(G,pos)
pylab.figure(2)
nx.draw(G,pos,node_size=60,font_size=8)
pylab.figure(3,figsize=(12,12))
nx.draw(G,pos)
pylab.show()


Well, the radius can be managed by the parameter 'scale' of nx.circular_layout(). And you can find more at https://networkx.github.io/documentation/latest/reference/generated/networkx.drawing.layout.circular_layout.html

0

精彩评论

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

关注公众号