title: Wrong colors for weighted edges in NetworkX
body: <p>after dealing with the following issue for far too long, I decided to put a post in here.</p>
  
  <p>I am trying to set up a networkx graph and color the edges according to some weight. Thing is, there seems to be a false assignment between edges and colors.</p>
  
  <p>Here is a simple code snippet.</p>
  
  <pre><code>#! /usr/bin/python
  # -*- coding: latin-1 -*-
  import networkx as nx
  import matplotlib.pyplot as plt
  import matplotlib.colors as colors
  
  # Set Up Data
  G=nx.Graph()
  G.add_node(0,pos=(0,0),label='0')
  G.add_node(1,pos=(0,1),label='1')
  G.add_node(2,pos=(1,0),label='2')
  G.add_node(3,pos=(1,1),label='3')
  
  G.add_edge(1,2, weight=3)
  G.add_edge(0,2, weight=5)
  G.add_edge(1,3, weight=2)
  G.add_edge(2,3, weight=1)
  G.add_edge(0,1, weight=4)
  
  # Attributes
  pos = nx.get_node_attributes(G,'pos')
  weights = nx.get_edge_attributes(G,'weight')
  labels = nx.get_node_attributes(G,'label')
  
  # Plot Figure
  fig = plt.figure()
  
  # Nodes
  nx.draw_networkx_nodes(G,pos)
  nx.draw_networkx_labels(G,pos,labels)
  
  # Edges
  out = nx.draw_networkx_edges(G,pos,edge_color = weights.values(), edge_cmap = plt.cm.jet, vmin = 0.0, vmax = max(weights.values()))
  nx.draw_networkx_edge_labels(G,pos,edge_labels=weights)
  plt.axis('off')
  
  # Set Up Colorbar
  cbar = plt.colorbar(out)
  
  # Show
  plt.show()
  </code></pre>
  
  <p>From this I get quite a strange assignment from edges to colors. Can anybody explain that? Did I do something wrong?</p>
  
  <p>Eventually, I found a workaround by sorting the colors.</p>
  
  <pre><code># Store edges
  sorted_edge = []
  sorted_edge.append((1,2))
  sorted_edge.append((0,2))
  sorted_edge.append((1,3))
  sorted_edge.append((2,3))
  sorted_edge.append((0,1))
  
  # Sort edges
  sorted_edge = sorted(sorted_edge)
  
  # Sort colors
  new_colors = []
  sorted_indices = [sorted_edge.index(edge) for edge in weights.keys()]
  for index in sorted_indices:
      while len(new_colors) &lt; index+1:
          new_colors.append(0)
      new_colors[index] = weights.values()[sorted_indices.index(index)]
  </code></pre>
  
  <p>Firstly, I would believe that this is not the intended solution to the issue?! Secondly, I am having a larger application of this small example where the assignment entirely fails, even with this sorting. Hence, I thought I'd better get a step back and try to understand what the issue is.</p>
  
  <p>Appreciate your answers.</p>
  
  <p>Best, Jonas</p>