简体   繁体   English

Networkx 在图的边缘定位节点

[英]Networkx position nodes at graph's edges

I'm very new to networkx graphs, so excuse me!我对 networkx 图表很陌生,请原谅! I was using this code to create a weighted network graph.我正在使用此代码创建加权网络图。 Which works perfectly!哪个工作得很好! But, I wanted to ask if there's a way to change the positions of all the nodes to be at the edges of the graph (with a circular layout) so it's clearer.但是,我想问一下是否有办法将所有节点的位置更改为位于图的边缘(使用圆形布局),以便更清晰。 Any ideas on how i could achieve this?关于我如何实现这一目标的任何想法?

This layout seems fine to me for the shared example.对于共享示例,这种布局对我来说似乎很好。 In Networkx however, you have several layouts which can be used to position the nodes in the graph.然而,在 Networkx 中,您有多种布局可用于在图中定位节点。 Based on your description, it looks like you might want a circular layout ( nx.circular_layout ) to have the nodes on the edges of the graph:根据您的描述,您似乎想要一个圆形布局 ( nx.circular_layout ) 在图形的边缘上放置节点:

plt.figure(figsize=(10,6))

pos = nx.circular_layout(G)  # positions for all nodes
# nodes
nx.draw_networkx_nodes(G, pos, node_size=700)
# edges
nx.draw_networkx_edges(G, pos, edgelist=elarge, width=6)
nx.draw_networkx_edges(
    G, pos, edgelist=esmall, width=6, alpha=0.5, edge_color="b", style="dashed"
)
# labels
nx.draw_networkx_labels(G, pos, font_size=20, font_family="sans-serif")

plt.axis("off")
plt.show()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM