我有一个带权重的圆形布局绘图。 我想让边从节点的外部开始,但找不到方法。我尝试设置alpha=1,但那并没有给我想要的结果。 下面的图片显示了我现在得到的结果。
这是我现在用于节点的代码:for n in G.nodes():
if n in set1:
G.nodes[n]['color'] = '#7a8eff'
elif n in set2:
G.nodes[n]['color'] = '#eb2c30'
elif n in set3:
G.nodes[n]['color'] = '#7300ff'
else:
G.nodes[n]['color'] = '#730a15'
colors = [node[1]['color'] for node in G.nodes(data=True)]
nx.draw_networkx_nodes(G, pos, node_size=1000, node_color=colors)
# edges
for edge in G.edges():
source, target = edge
rad = 0.25
node_color_dict = dict(G.nodes(data='color'))
if node_color_dict[source] == node_color_dict[target]:
arrowprops=dict(lw=G.edges[(source,target)]['weight'],
arrowstyle="-",
color='blue',
connectionstyle=f"arc3,rad={rad}",
linestyle= '-',
alpha=0.45)
ax.annotate("",
xy=pos[source],
xytext=pos[target],
arrowprops=arrowprops
)
else:
arrowprops=dict(lw=G.edges[(source,target)]['weight'],
arrowstyle="-",
color='purple',
connectionstyle=f"arc3,rad={rad}",
linestyle= '-',
alpha=0.45)
ax.annotate("",
xy=pos[source],
xytext=pos[target],
arrowprops=arrowprops
)
# labels
nx.draw_networkx_labels(G, pos, font_size=11, font_family="monospace", font_color='white', font_weight='bold', alpha=1.0)
nx.draw
,我无法重现问题,我们需要完整的代码来帮助您。我猜您首先绘制节点,然后再绘制边缘。更改此顺序可能会解决问题。如果您添加一个最小可重现示例,那么帮助您就会变得更加容易。 - Sparky05zorder
添加到arrowprops
应该可以解决您的问题。我已经在下面扩展了代码示例。 - Sparky05nx.draw_networkx_labels(G, pos, font_size=11, font_family="monospace", font_color='white', font_weight='bold')
绘制标签。 - nandz123