title: Import graph from graphml restoring node positions with NetworkX
body: <p>I'm saving a graph with node positions in graphml format.</p>
  
  <p>I want to load it and draw its nodes in the same positions as before. Data saved in the graphml file consists of primitive types, whereas data used by <code>mathplotlib</code> to draw the graph is a dictionary <code>{string: array([x, y]), dtype=float32}</code>, where the <code>array</code> is most probably a <code>numpy</code> array.</p>
  
  <p>I'm using NetworkX 1.9.1, and this is my code. I guess the problem may be due messy iteration. Plus, I can't build from scratch the structure used to draw positions.</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  import numpy as np
  
  #load the graph from the graphml file
  def load_graph(file_path):
      G = nx.read_graphml(file_path)
      return G
  
  def show_graph(G):
      #used to create the structure, computation useless
      pos = nx.circular_layout(G)
  
      print(pos)
  
      #try to refill the structure (don't produce expected results)
      for (node, node_pos) in pos.items():
          node_pos[0] = G.node[node]['x']
          node_pos[1] = G.node[node]['y']
  
      #draw the graph
      print(pos)
      plt.clf()
      nx.draw_networkx(G, pos)
      plt.show()
  
  file_path = 'netw_a.graphml'
  A = load_graph(file_path)
  show_graph(A)
  </code></pre>
  
  <p>Here is a test file for import</p>
  
  <pre><code>&lt;graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd"&gt;
    &lt;key attr.name="x" attr.type="double" for="node" id="d2" /&gt;
    &lt;key attr.name="y" attr.type="double" for="node" id="d1" /&gt;
    &lt;key attr.name="name" attr.type="string" for="graph" id="d0" /&gt;
    &lt;graph edgedefault="undirected"&gt;
      &lt;data key="d0"&gt;path_graph(4)&lt;/data&gt;
      &lt;node id="0"&gt;
        &lt;data key="d1"&gt;0.394087123189&lt;/data&gt;
        &lt;data key="d2"&gt;0.0&lt;/data&gt;
      &lt;/node&gt;
      &lt;node id="1"&gt;
        &lt;data key="d1"&gt;0.743297296307&lt;/data&gt;
        &lt;data key="d2"&gt;0.402465740641&lt;/data&gt;
      &lt;/node&gt;
      &lt;node id="2"&gt;
        &lt;data key="d1"&gt;0.529781867707&lt;/data&gt;
        &lt;data key="d2"&gt;0.942892202945&lt;/data&gt;
      &lt;/node&gt;
      &lt;node id="3"&gt;
        &lt;data key="d1"&gt;0.0&lt;/data&gt;
        &lt;data key="d2"&gt;1.0&lt;/data&gt;
      &lt;/node&gt;
      &lt;edge source="0" target="1" /&gt;
      &lt;edge source="1" target="2" /&gt;
      &lt;edge source="2" target="3" /&gt;
    &lt;/graph&gt;
  &lt;/graphml&gt;
  </code></pre>