Reputation: 21
How do I select a range from given values when drawing degree_centrality
graph.
B1: 0.64
E2: 0.61
C3: 0.60
B2: 0.58
M1: 0.50
C1: 0.328
R1: 0.228
def draw(G, pos, measures, measure_name):
nodes = nx.draw_networkx_nodes(G, pos, node_size=250, cmap=plt.cm.plasma,
node_color=list(measures.values()),
nodelist=measures.keys())
nodes.set_norm(mcolors.SymLogNorm(linthresh=0.01, linscale=1, base=10))
# labels = nx.draw_networkx_labels(G, pos)
edges = nx.draw_networkx_edges(G, pos)
plt.title(measure_name)
plt.colorbar(nodes)
plt.axis('off')
plt.show()
pos = nx.spring_layout(G, seed=675)
draw(G, pos, nx.degree_centrality(G), 'Degree Centrality')
I am trying to use Network centrality measure visualisation to draw visualise centrality measure but i am only interested in visualising nodes within a range of values.
I only wany to visualise range 0.64 to 0.60 from the given range above.
B1: 0.64
E2: 0.61
C3: 0.60
Upvotes: 1
Views: 136
Reputation: 16561
One way is to reduce the dictionary measures
:
def draw(G, pos, measures, measure_name):
# reduce measures
min_val, max_val = 0.1, 0.4
measures = {k:v for k, v in measures.items() if v<=max_val and v>=min_val}
...
Note that the min_val
, max_val
can be added as arguments of the function or alternatively, the subsetting can be done before passing values to the function (so calculate the centrality measure separately, subset it, and only after pass it to the function).
Upvotes: 1