开发者

draw_networkx() in networkx

开发者 https://www.devze.com 2023-03-02 00:17 出处:网络
I am getting this error when trying networkx net开发者_JS百科workx.draw_networkx(G,ax = self.axes)

I am getting this error when trying networkx

net开发者_JS百科workx.draw_networkx(G,ax = self.axes)
TypeError: draw_networkx() takes at least 2 non-keyword arguments (1 given)

The code for the same is

G=networkx.Graph()
G.add_node("spam")
G.add_edge(1,2)
networkx.draw_networkx(G,ax = self.axes)

Can someone explain what am I doing wrong and how can I correct this.... The link for the function is draw_networkx.

Thanks


It is expecting the pos argument, to inform the drawing routine how to position the nodes. Here's how you can use a spring layout to populate pos:

networkx.draw_networkx(G, pos=networkx.spring_layout(G), ax=self.axes)

Output:

draw_networkx() in networkx


samplebias gave a great example.

If you want an even simpler way to do it for command line analysis or messing around:

networkx.draw_spring(G)

It's a built in method for drawing based on spring weights and honors weights so you can include stuff like:

G=networkx.Graph()
G.add_node("spam")
G.add_edge(1,2,weight=4.7)
G.add_edge(1,"spam")

And the 1-2 connection will be shorter than the 1-spam connection due to spring weighting. Very quick and easy.

0

精彩评论

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