我有nx.DiGraph
这样的人(玩具示例)
import networkx as nx
G = nx.DiGraph()
G.add_node('a', weight= 1)
G.add_node('b', weight= 2)
G.add_node('c', weight= 3)
G.add_edge('a', 'b', range = 10)
G.add_edge( 'b','a', range = 20)
G.add_edge('a', 'c', range = 10)
G.add_edge( 'c','a', range = 20)
G.add_edge('c', 'b', range = 10)
G.add_edge( 'b','c', range = 20)
然后我像波纹管一样抽奖
plt.figure(figsize=(5,5))
edge_labels = nx.get_edge_attributes(G,'range')
edge_size= [edge_labels[v] for v in edge_labels]
node_labels = nx.get_node_attributes(G,'weight')
node_size = [node_labels[v] for v in node_labels]
pos = nx.spring_layout(G) # circularspring_layout, scale=1., center=None
nx.draw_networkx_edge_labels(G,pos, edge_labels = edge_labels, font_size=25, font_color='k')
nx.draw_networkx(G, pos, node_size=[d['weight']*2000 for _, d in G.nodes(data=True)], edge_color='.4',
node_color= [d['weight'] for _, d in G.nodes(data=True)], alpha=0.6,with_labels=True, width = [d['range'] for _, _, d in G.edges(data=True)],
cmap=plt.cm.seismic, font_size =30, arrows = False) #
plt.axis('off')
plt.tight_layout()
plt.show()
我想在绘制上显示边缘标签(边缘属性“范围”),但是一个标签叠加在另一个标签上,我们只能看到一个标签(仅range
= 10,但是有{{1} } = 20)。如何解决?