Networkx position nodes at graph's edges

Viewed 284

I'm very new to networkx graphs, so excuse me! 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?

1 Answers

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. 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:

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

enter image description here

Related