Abhinav Wadhwa
Abhinav Wadhwa

Reputation: 21

Draw a ring topology using python

I need to draw a topology similar to shown in the picture below. But I am not able to arrange the order of the node and also how to stop edges from crossing randomly.

Image

Upvotes: 1

Views: 726

Answers (1)

Geom
Geom

Reputation: 1546

You can hardcode the positions like this:

G = nx.DiGraph()

G.add_node(0,pos=(20,20))
G.add_node(1,pos=(30,10))
G.add_node(2,pos=(25,0))
G.add_node(3,pos=(15,0))
G.add_node(4,pos=(10,10))
pos=nx.get_node_attributes(G,'pos')

G.add_edge(0, 1)
G.add_edge(1, 2)
G.add_edge(2, 3)
G.add_edge(3, 4)
G.add_edge(4, 0)

nx.draw(G,pos=pos, with_labels=True, font_weight='bold', node_size=1000, node_color = 'black',font_color = 'white')
plt.show()

Result:

enter image description here

Upvotes: 2

Related Questions