在networkx中创建输入箭头

2024-04-27 01:13:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否可以创建某种符号来指示networkx/Python中的图形输入。在

例如,以呈现的图像here为例,假设我希望能够识别源和汇。我有兴趣创建一个代表,如:

enter image description here

有可能吗?在


Tags: 图像networkx图形here符号代表兴趣
1条回答
网友
1楼 · 发布于 2024-04-27 01:13:48

annotate功能正是您想要的。(另见annotate intro

给定链接的示例,您只需添加以下内容来注释选定的节点。(这取决于位置字典pos来知道节点的位置)。在

ax = plt.gca()
ax.annotate("3", xy=pos.get('B'), xytext=(0, 40), textcoords='offset points',
    arrowprops=dict(facecolor='black', shrink=0.15),  
    bbox=dict(boxstyle="round", fc="cyan"))
ax.annotate("4", xy=pos.get('F'), xytext=(0, 40), textcoords='offset points',
    arrowprops=dict(facecolor='black', shrink=0.15),
    bbox=dict(boxstyle="round", fc="cyan"))

example networkx with annotation

所以这个答案是自包含的完整代码,包括linked example

^{pr2}$

相关问题 更多 >