gman1200
gman1200

Reputation: 39

Is it possible to draw in networkx using current node placement in figure?

I have matlibplot and networkx. I have generated graph and i want to remove edges, but I want also to have vertices in the same place. Is it possible with this python stack containing: networx and matlibplot? For example

    self.figure.clf()
    self.axes = self.figure.add_subplot(111)

    print 'generate random graph'
    self.G.remove_edge(0,1)
    self.G.remove_edge(0,2)
    nx.draw(self.G, node_color='c',edge_color='k', with_labels=True, ax=self.axes)

    self.canvas.draw()

here I want to remove edges, but after nx.draw node placement is not in the same position

Upvotes: 0

Views: 395

Answers (1)

Haochen Wu
Haochen Wu

Reputation: 1823

In networkX, the function draw have a parameter pos and it can take a dictionary to specify each node's position.

Refer the document here: https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.drawing.nx_pylab.draw.html#draw

Further more, to automatically generate such a dictionary, networkX provides many ways organized in the layout section.

Refer the document here: https://networkx.github.io/documentation/development/reference/drawing.html?highlight=layout#module-networkx.drawing.layout

If you draw two graphs with the same position dictionary, all the nodes will be at the same position.

Upvotes: 1

Related Questions