我正在try 编写Python代码,希望能够更改每条边的宽度.
这是我到目前为止的代码:
import matplotlib.pyplot as plt
import networkx as nx
# create Graph
g = nx.Graph()
# add nodes to graph
g.add_node(1)
g.add_node(2)
g.add_node(3)
g.add_node(4)
g.add_node(5)
g.add_node(6)
g.add_node(7)
g.add_node(8)
g.add_node(9)
g.add_node(10)
g.add_node(11)
g.add_node(12)
g.add_node(13)
g.add_node(14)
g.add_node(15)
g.add_node(16)
g.add_node(17)
g.add_node(18)
g.add_node(19)
g.add_node(20)
g.add_node(21)
# add edges between nodes
g.add_edge(1, 2,width=1)
g.add_edge(1, 3,width=10)
g.add_edge(2, 3,width=10)
g.add_edge(3, 4,width=10)
g.add_edge(4, 5,width=1)
g.add_edge(5, 6,width=10)
g.add_edge(5, 7,width=10)
g.add_edge(6, 7,width=10)
g.add_edge(5, 9,width=10)
g.add_edge(6, 9,width=10)
g.add_edge(7, 8,width=10)
g.add_edge(6, 10,width=10)
g.add_edge(10, 11,width=10)
g.add_edge(6, 11,width=10)
g.add_edge(11, 12,width=10)
g.add_edge(9, 10,width=10)
g.add_edge(9, 15,width=10)
g.add_edge(10, 13,width=10)
g.add_edge(12, 13,width=10)
g.add_edge(13, 14,width=10)
g.add_edge(14, 16,width=10)
g.add_edge(15, 14,width=10)
g.add_edge(9, 14,width=10)
g.add_edge(16, 17,width=10)
g.add_edge(13, 18,width=10)
g.add_edge(17, 18,width=10)
g.add_edge(17, 20,width=10)
g.add_edge(17, 19,widht=10)
g.add_edge(19, 20,width=10)
g.add_edge(18, 20,width=10)
g.add_edge(19, 21,width=10)
g.add_edge(20, 21,width=10)
widths = list(nx.get_edge_attributes(g,'width').values())
# position of nodes of Graph
pos={
1:(13,78),
2:(24,87),
3:(23,77),
4:(25,68),
5:(27,59),
6:(27,46),
7:(17,49),
8:(5,36),
9:(42,58),
10:(40,36),
11:(35,31),
12:(40,12),
13:(61,30),
14:(70,43),
15:(72,55),
16:(82,40),
17:(83,20),
18:(77,15),
19:(93,14),
20:(88,9),
21:(97,4),
}
# drawing graph and specifying properties(node color, edge color, line width, etc)
nx.draw(g, pos, with_labels=True,node_color="orange", node_size=300, edge_color="black", width=list(widths))
# The graph title and showing it
plt.title('Gabriel Graph (102)')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
问题是,我有所有的边缘宽度设置为10,除了2,但输出显示三个边缘的宽度为1.
以下是指向输出的链接:https://i.stack.imgur.com/akgwo.png
有谁能帮我修一下这个吗?