我正在使用networkx并matplotlib绘制网络图.我已经为每个节点关联了一个浮点形式的标签(最多两个小数点).我希望标签在图表中更加醒目.是否有任何类型的解决方法可以提供更好的标签可见性?
更新:我在这里找到了类似的问题,并尝试应用该解决方案.事实证明,解决方案的效果非常糟糕.
代码如下:
label_ratio = 1.0/8.0
pos_labels = {}
#For each node in the Graph
for node in network.graph.nodes():
#Get the node's position from the layout
x,y = network.position[node]
#Get the node's neighbourhood
N = network.graph[node]
#Find the centroid of the neighbourhood. The centroid is the average of the Neighbourhood's node's x and y coordinates respectively.
#Please note: This could be optimised further
cx = sum(map(lambda x:pos[x][0], N)) / len(pos)
cy = sum(map(lambda x:pos[x][1], …Run Code Online (Sandbox Code Playgroud)