I am drawing a network and I want node sizes to be dependent on specific values for each node, but these values can sometimes be negative. When I input the vector of values as the node_size
argument of the draw_networkx_nodes
function (and multiply by *300), I get the following output;
"Negative" node sizes are not displayed, the problem being (I think) that the negative values are taken 'as such' for node sizes, and hence considered as "very low".
I want the "scale" of the node sizes to "start" at the lowest value (which will be negative) of the node size vector
For inspiration regarding the desired output : Screenshot of an article with desired result
Sample of code ;
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
nodesize_test=np.array([-0.1,0.8,0.3])
adj_matrix = np.array([[0. , 0.72105342, 0.76595857],
[0.72105342, 0. , 0.85544021],
[0.76595857, 0.85544021, 0. ]])
G= nx.Graph(adj_matrix)
nodelist= list(G.nodes()) #Retrieve list of nodes
pos = nx.spring_layout(G)
ec = nx.draw_networkx_edges(G, pos)
nc = nx.draw_networkx_nodes(G, pos, nodelist=nodelist,node_size=nodesize_test*300)
plt.show()
PS. Scaling the vector to [0,1] seems not to be an acceptable solution as it impacts the relative node sizes (i.e. the quotient between two node sizes) and hence the information displayed. For instance, after rescaling using this, the ratio between 2nd and 3rd node sizes shifts from 2.67 (unscaled) to 2.25 (scaled). The information is not the same anymore: node 2 should not be 2.25x bigger but rather 2.67x bigger than node 3.