title: Python: how to color the nodes of a network according to their degree?
body: <p>I have a scale-free network made of <code>10000</code> nodes, but the texture of edges and the number of nodes make it too intricate to be made sense of. <em>I want to be able to visually locate the most highly connected nodes.</em></p>
  
  <p><strong>How could I color the nodes based on their degree k?</strong> Specifically, I would like to color them based on pre-assigned ranges, such as:</p>
  
  <ul>
  <li>Green if <code>1&lt;k&lt;10</code>; </li>
  <li>Light blue if <code>11&lt;k&lt;20</code>;</li>
  <li>Blue if <code>21&lt;k&lt;30</code>;</li>
  <li>Purple if <code>31&lt;k&lt;40</code>;</li>
  <li>...</li>
  </ul>
  
  <p>Here is how I obtain the network:</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  n = 10000  # Number of nodes
  m = 3  # Number of initial links
  seed = 500
  G = nx.barabasi_albert_graph(n, m, seed)
  ncols = 100
  pos = {i : (i % ncols, (n-i-1)//ncols) for i in G.nodes()}
  fig, ax = plt.subplots()
  nx.draw(G, pos, with_labels=False, ax=ax, node_size=10)
  degrees=G.degree() #Dict with Node ID, Degree
  sum_of_degrees=sum(degrees.values()) #Sum of degrees
  avg_degree_unaltered=sum_of_degrees/10000 #The average degree &lt;k&gt;
  short_path=nx.average_shortest_path_length(G)
  print('seed: '+str(seed)+', short path: '+str(round(short_path,3))+', log(N)=4')
  #Plot the graph
  plt.xlim(-20,120,10)
  plt.xticks(numpy.arange(-20, 130, 20.0))
  plt.ylim(120,-20,10) 
  plt.yticks(numpy.arange(-20, 130, 20.0))
  plt.axis('on')
  title_string=('Scale-Free Network') 
  subtitle_string=('100x100'+' = '+str(n)+' nodes')
  plt.suptitle(title_string, y=0.99, fontsize=17)
  plt.title(subtitle_string, fontsize=8)
  plt.show()
  </code></pre>
  
  <p>This is the result without applying the differential coloring. <strong>PS:</strong> the initial node with ID 0 is in the top left corner.
  <a href="https://i.stack.imgur.com/R8rNi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R8rNi.png" alt="enter image description here"></a></p>