网络中的边长x [英] edge length in networkx

查看:56
本文介绍了网络中的边长x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过以下代码调整两个节点之间的边长.但显然它不起作用.谁能指导我哪里出错了:请注意,我已经看过这个线程(

您还可以使用 draw_networkx_edge_labels 的参数来准确打印出您想要的内容.

I am trying to adjust the length of edge between two nodes by following code. But apparently it didn't work. Could anyone guide me where I am making mistake: Please note that I already look at this thread (How to specify edge length in Networkx for calculating shortest distance?) but didn't solve my issue

import networkx as nx
import matplotlib.pyplot as plt

G=nx.Graph()
G.add_nodes_from([1,2])
G.add_edge(1,2, length = 10)  # I also replaced length with len but no luck
nx.draw(G,with_labels=True)
plt.show() # display

解决方案

How about this:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_nodes_from([1,2])
G.add_edge(1,2, length = 10)
pos = nx.spring_layout(G)
nx.draw(G, pos)
nx.draw_networkx_edge_labels(G, pos)
plt.show()

It will look like this:

You can also play around with draw_networkx_edge_labels's parameters to print out just exactly what you want.

这篇关于网络中的边长x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆