I use networkxand matplotlibfor drawing the network schedule. I associated with each node a label in the form of a float (up to two decimal places). I was hoping the labels would become more visible on the chart. Is there any solution that can improve the visibility of labels?

Update: I found a similar question here and tried to apply a solution. The decision turned out to be rather unsuccessful, as it turned out.

The code is as follows:
label_ratio = 1.0/8.0
pos_labels = {}
for node in network.graph.nodes():
x,y = network.position[node]
N = network.graph[node]
cx = sum(map(lambda x:pos[x][0], N)) / len(pos)
cy = sum(map(lambda x:pos[x][1], N)) / len(pos)
slopeY = (y-cy)
slopeX = (x-cx)
pos_labels[node] = (x+slopeX*label_ratio, y+slopeY*label_ratio)
nx.draw(G, pos, ax=axis, node_size=20, with_labels=False)
nx.draw_networkx_labels(G, pos_labels, labels, font_size=7, font_color='b', ax=axis)
source
share