使用箭头时边未完全连接节点

问题描述 投票:0回答:1

我想使用弯曲边缘绘制图表 (

connectionstyle="arc3, rad=0.3"
)。

来自警告

arrowstyle 关键字参数在绘制边缘时不适用
与 LineCollection 一起。

要消除此警告,请指定“arrows=True”
强制 FancyArrowPatches 或使用默认值。
请注意,对于大型图形,使用 FancyArrowPatches 可能会很慢。

我使用

arrows=True
产生以下代码片段:

import networkx as nx

G = nx.gnm_random_graph(n=1000, m=100)
fig, ax = plt.subplots(dpi=300)
nx.draw_networkx_nodes(G, pos, edgecolors='black', node_size=20, linewidths=0.25, ax=ax)
nx.draw_networkx_edges(G, pos, width=0.5, connectionstyle="arc3, rad=0.3", edge_color='gray', arrows=True, min_source_margin=0, min_target_margin=0, ax=ax)

但是,边缘(弯曲或不弯曲)并未完全连接节点:

enter image description here

我做错了什么?

matplotlib networkx
1个回答
0
投票

问题是

node_size
参数不匹配。
draw_networkx_edges
中的默认值为 300,而不是 20。

Sample code output

import matplotlib.pyplot as plt
import networkx as nx

G = nx.gnm_random_graph(n=1000, m=100)
pos = nx.random_layout(G)
fig, ax = plt.subplots(dpi=300)
nx.draw_networkx_nodes(G, pos, edgecolors='black', node_size=20, linewidths=0.25, ax=ax)
nx.draw_networkx_edges(G, pos, width=0.5, connectionstyle="arc3, rad=0.3", edge_color='gray', arrows=True, min_source_margin=0, min_target_margin=0, node_size=20, ax=ax)
plt.show()
© www.soinside.com 2019 - 2024. All rights reserved.