title: Setting colors in draw_networkx and in matplotlib
body: <p>I'm drawing two types of figures, for which I want to align the colors:</p>
  
  <ol>
  <li>The color of the nodes in a networkx.Graph, and</li>
  <li>the color of pyplot.hlines in a regular plot.</li>
  </ol>
  
  <p>Both figures rely on a dictionary with node_names as keys, and ints as values, and a <code>matplotlib.colors.LinearSegmentedColormap</code> cmap. Like the following:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  Dict = {"Alice": 0, "Bob": 1, "Carol": 2}
  cmap = plt.cm.Accent
  </code></pre>
  
  <p>This allows me to get a unique color for each name. For this example:</p>
  
  <pre><code>for key, value in Dict.iteritems():
      print key, value, cmap(value)
  </code></pre>
  
  <p>gives me</p>
  
  <pre><code>Bob 1 (0.50482122313742539, 0.78532873251858881, 0.50718954287323292, 1.0)
  Alice 0 (0.49803921580314636, 0.78823530673980713, 0.49803921580314636, 1.0)
  Carol 2 (0.51160323047170453, 0.7824221582973705, 0.5163398699433196, 1.0)
  </code></pre>
  
  <p>Which can be used as follows:</p>
  
  <pre><code>plt.hlines(1, 1, 5, cmap(Dict["Alice"]))
  plt.hlines(2, 1, 5, cmap(Dict["Bob"]))
  plt.hlines(3, 1, 5, cmap(Dict["Carol"]))
  </code></pre>
  
  <p>These values, however, do not at all match the result I get when I draw the following network:</p>
  
  <pre><code>G = nx.Graph()
  G.add_nodes_from(Dict.keys())
  nx.draw_networkx(G, nodelist=Dict.keys(), node_color=range(3), \
  cmap=plt.cm.Accent)
  </code></pre>
  
  <p>For the plot of the network I get 3 clearly distinct colors, but for the hlines they are virtually indistinguishable.</p>
  
  <p>What am I missing about how <code>nx.draw_networkx</code>uses <code>node_color</code> and <code>cmap</code>?</p>