【问题标题】:Curved edges using matplotlib and Networkx in Python 3.x在 Python 3.x 中使用 matplotlib 和 Networkx 的曲线边缘
【发布时间】:2020-02-29 10:48:58
【问题描述】:

我想使用 Networkx 框架和 matplotlib 绘制曲线边缘。

与下面链接的问题基本相同:

Networkx: Overlapping edges when visualizing MultiGraph

一个答案是:

import networkx as nx
G = nx.DiGraph()
G.add_nodes_from([0,1])
pos = nx.circular_layout(G)
nx.draw_networkx_nodes(G, pos, connectionstyle='arc3, rad = 0.1', node_color = 'r', node_size = 100, alpha = 1)
nx.draw_networkx_edges(G, pos,connectionstyle='arc3, rad = 0.1', edgelist = [(0,1)], width = 2, alpha = 0.5, edge_color='b')
nx.draw_networkx_edges(G, pos,connectionstyle='arc3, rad = 0.1', edgelist= [(1,0)], width = 1, alpha = 1)
plt.axis('off')
plt.show() 

但这会产生:

最后我想制作这样的东西:

【问题讨论】:

标签: python matplotlib networkx


【解决方案1】:

我认为您不能直接使用 networkx 函数来执行此操作。但是您可以使用您计算的节点位置直接使用 matplotlib。

例如基于this:

import networkx as nx
G = nx.DiGraph()
G.add_nodes_from([0,1])
pos = nx.circular_layout(G)
nx.draw_networkx_nodes(G, pos, node_color = 'r', node_size = 100, alpha = 1)
ax = plt.gca()
ax.annotate("",
                xy=pos[0], xycoords='data',
                xytext=pos[1], textcoords='data',
                arrowprops=dict(arrowstyle="->", color="0.5",
                                shrinkA=5, shrinkB=5,
                                patchA=None, patchB=None,
                                connectionstyle="arc3,rad=0.3",
                                ),
                )
plt.axis('off')
plt.show()

给予:

【讨论】:

    猜你喜欢
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2021-06-22
    • 2021-06-03
    • 2013-03-16
    • 1970-01-01
    相关资源
    最近更新 更多