How to make node labels more visible in matplotlib

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?

Matplotlib Chart

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.

MatplotLib Attempted Solution

The code is as follows:

label_ratio = 1.0/8.0
    pos_labels = {} 
    #For each node in the Graph
    for node in network.graph.nodes():
        #Get the node position from the layout
        x,y = network.position[node]
        #Get the node neighbourhood
        N = network.graph[node]
        #Find the centroid of the neighbourhood. The centroid is the average of the Neighbourhood node 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], N)) / len(pos)
        #Get the centroid 'direction' or 'slope'. That is, the direction TOWARDS the centroid FROM aNode.
        slopeY = (y-cy)
        slopeX = (x-cx)
        #Position the label at some distance along this line. Here, the label is positioned at about 1/8th of the distance.
        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)
+4
source share
1 answer

NetworkX is not effective enough for drawing large graphs, since it provides only basic functions for visualizing graphs.

node , node . , . Gephi, .

.

  • 1. NetworkX , .gramph
  • 2. Gephi
  • 3. Matplotlib Gephi.

NetworkX:


, , Gephi ( YifanHu, , → (, ) → ). , NetworkX?

enter image description here

+4

Source: https://habr.com/ru/post/1661729/


All Articles