小编adr*_*aat的帖子

NetworkX节点标签的相对位置

我正在努力解决以下问题。我想根据以前进行的分类,绘制一个大约100个节点的圆形图,必须在其中手动定位它们。这些节点有一个分配的标签,这些标签用不同的文本长度来描述它们,我想将此标签与节点相邻。下图是我要获取的图形(我画了一个蓝色圆圈,只是为了表明标签在外围完全对齐):https : //i.stack.imgur.com/Qre0Z.png

到目前为止,我只能做到这一点:https : //i.stack.imgur.com/U7bZG.png

这是MWE:

import numpy as np
import networkx as nx
import matplotlib.pyplot as plt

n = 7
G = nx.complete_graph(n)
node_list = sorted(G.nodes())
angle = []
angle_dict = {}
for i, node in zip(xrange(n),node_list):
    theta = 2.0*np.pi*i/n
    angle.append((np.cos(theta),np.sin(theta)))
    angle_dict[node] = theta
pos = {}
for node_i, node in enumerate(node_list):
    pos[node] = angle[node_i]

labels = {0:'zero',1:'oneone',2:'twotwo',3:'threethreethree',4:'fourfourfourfour',5:'fivefivefivefivefive',6:'sixsixsixsixsixsix'}

# figsize is intentionally set small to condense the graph
f = plt.figure(figsize=(2,2))
r = f.canvas.get_renderer()
plt.axis('equal')
nx.draw(G,pos=pos,with_labels=True) …
Run Code Online (Sandbox Code Playgroud)

python graph matplotlib networkx

4
推荐指数
1
解决办法
2310
查看次数

标签 统计

graph ×1

matplotlib ×1

networkx ×1

python ×1