title: Export graph to graphml with node positions using NetworkX
body: <p>I'm using NetworkX 1.9.1.</p>
  
  <p>I have a graph that I need to organize with positions and I then export to graphml format.</p>
  
  <p>I've tried code in <a href="https://stackoverflow.com/q/7591154">this question</a>. It does not work, here is my example</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  G = nx.read_graphml("colored.graphml")
  
  pos=nx.spring_layout(G) # an example of quick positioning
  nx.set_node_attributes(G, 'pos', pos)
  
  nx.write_graphml(G, "g.graphml")
  
  nx.draw_networkx(G, pos)
  plt.savefig("g.pdf")
  </code></pre>
  
  <p>Here are the errors I get, the problem is how positions are saved (graphml does not accept arrays).</p>
  
  <pre><code>C:\Anaconda\python.exe C:/Users/sturaroa/Documents/PycharmProjects/node_labeling_test.py
  Traceback (most recent call last):
    File "C:/Users/sturaroa/Documents/PycharmProjects/node_labeling_test.py", line 11, in &lt;module&gt;
      nx.write_graphml(G, "g.graphml")
    File "&lt;string&gt;", line 2, in write_graphml
    File "C:\Anaconda\lib\site-packages\networkx\utils\decorators.py", line 220, in _open_file
      result = func(*new_args, **kwargs)
    File "C:\Anaconda\lib\site-packages\networkx\readwrite\graphml.py", line 82, in write_graphml
      writer.add_graph_element(G)
    File "C:\Anaconda\lib\site-packages\networkx\readwrite\graphml.py", line 350, in add_graph_element
      self.add_nodes(G,graph_element)
    File "C:\Anaconda\lib\site-packages\networkx\readwrite\graphml.py", line 307, in add_nodes
      self.add_attributes("node", node_element, data, default)
    File "C:\Anaconda\lib\site-packages\networkx\readwrite\graphml.py", line 300, in add_attributes
      scope=scope, default=default_value)
    File "C:\Anaconda\lib\site-packages\networkx\readwrite\graphml.py", line 288, in add_data
      '%s as data values.'%element_type)
  networkx.exception.NetworkXError: GraphML writer does not support &lt;type 'numpy.ndarray'&gt; as data values.
  </code></pre>
  
  <p>I'm under the impression that I would be better off defining positions as 2 separate node attributes, x and y, and save them separately, defining a key for each of them in the graphml format, <a href="http://graphml.graphdrawing.org/primer/graphml-primer.html#AttributesValues" rel="nofollow noreferrer">like this</a>.</p>
  
  <p>However, I'm not that familiar with Python, and would like your opinion before I make a mess iterating back and forth.</p>
  
  <p>Thanks.</p>