title: Add edge-weights to plot output in networkx from adjacency matrix
body: <p>I'm generating a random graph and drawing it from the adjacency matrix. I need to be able to add the edge weights. </p>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/28372127/add-edge-weights-to-plot-output-in-networkx">Add edge-weights to plot output in networkx</a> and that seems to work fine and is exactly what I'm looking for in the display, but it only works when adding edges individually.</p>
  
  <p>I'm using:
  nx.from_numpy_matrix(G, create_using = nx.DiGraph()) </p>
  
  <p>And according to <a href="https://networkx.github.io/documentation/networkx-1.10/reference/generated/networkx.convert_matrix.from_numpy_matrix.html?highlight=from_numpy_matrix#from-numpy-matrix" rel="nofollow noreferrer">the documentation</a>, if the nonsymmetric adjacency matrix has only integer entries (which it does), the entries will be interpreted as weighted edges joining the vertices (without creating parallel edges). So when looking at <a href="https://stackoverflow.com/questions/28372127/add-edge-weights-to-plot-output-in-networkx">Add edge-weights to plot output in networkx</a>, they grab the node attributes, grab the label attributes, and draw the edge labels. But I'm unable to grab the attributes. Does anyone know how to display these edges while still using this adjacency matrix?</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>from random import random
  import numpy
  import networkx as nx
  import matplotlib.pyplot as plt
  
  #here's how I'm generating my random matrix
  def CreateRandMatrix( numnodes = int):
      def RandomHelper():
          x = random()
          if x &lt; .70:
              return(0)
          elif .7 &lt;= x and x &lt;.82:
              return(1)
          elif .82 &lt;= x and x &lt;.94:
              return(2)
          else:
              return(3)
      randomatrix = numpy.matrix([[RandomHelper() for x in range(numnodes)] for y in range(numnodes)])
      for i in range(len(randomatrix)):
          randomatrix[i,i]=0
      return randomatrix
  
  #this generate the graph I want to display edge weights on
  def Draw(n = int): 
      MatrixtoDraw = CreateRandMatrix(n)
      G = nx.from_numpy_matrix(MatrixtoDraw, create_using = nx.DiGraph())
      nx.draw_spring(G, title="RandMatrix",with_labels=True)
      plt.show()
  </code></pre>
  
  <p>This my attempt at following <a href="https://stackoverflow.com/questions/28372127/add-edge-weights-to-plot-output-in-networkx">Add edge-weights to plot output in networkx</a>.</p>
  
  <pre><code>def Draw2(n = int):
      MatrixtoDraw = CreateRandMatrix(n)
      G = nx.from_numpy_matrix(MatrixtoDraw, create_using = nx.DiGraph())
      nx.draw_spring(G, title="RandMatrix",with_labels=True)
      pos=nx.get_node_attributes(G,'pos')
      labels = nx.get_edge_attributes(G,'weight')
      nx.draw_networkx_edge_labels(G,pos,edge_labels=labels)
      plt.show()
  </code></pre>
  
  <p>If I run each line individually on idle I get </p>
  
  <pre><code>&gt;&gt;&gt; nx.get_node_attributes(G,'pos')
  {}
  &gt;&gt;&gt; nx.get_node_attributes(G,'weight')
  {}
  </code></pre>
  
  <p>Why are they not being grabbed from the graph information generated by the adjacency matrix?</p>