小编g3n*_*5i5的帖子

在Python3中使用NetworkX创建弯曲的边缘

我想使用networkx(如果您知道更好的框架,我也想采用其他框架)来创建节点位于固定位置的抓图。同时,图形的边缘不应重叠。

我之前的代码如下:

#!/usr/bin/env python3

import networkx as nx
import matplotlib.pyplot as plt

# Graph data
names = ['A', 'B', 'C', 'D', 'E']
positions = [(0, 0), (0, 1), (1, 0), (0.5, 0.5), (1, 1)]
edges = [('A', 'B'), ('A', 'C'), ('A', 'D'), ('A', 'E'), ('D', 'A')]

# Matplotlib figure
plt.figure('My graph problem')

# Create graph
G = nx.MultiDiGraph(format='png', directed=True)

for index, name in enumerate(names):
    G.add_node(name, pos=positions[index])

labels = {}
for edge in edges:
    G.add_edge(edge[0], edge[1])
    labels[(edge[0], edge[1])] = '{} -> …
Run Code Online (Sandbox Code Playgroud)

python graph directed-graph matplotlib networkx

5
推荐指数
3
解决办法
1682
查看次数

标签 统计

directed-graph ×1

graph ×1

matplotlib ×1

networkx ×1

python ×1