title: Is there a way to add a tuple of position as an attribute to a created node in networkx?
body: <p>I'm trying to get the position of all the nodes that are being made into my graph. The current goal is to create all the nodes which possess an <code>x</code> and <code>y</code> coordinate.</p>
  <p>What I was reading is about attributes when using <code>add_nodes_from()</code> and possibly create a position attribute for my nodes. Reading a little bit of documentation and another StackOverflow is unsuccessful for me.</p>
  <p>ex.txt file:</p>
  <pre><code>a2a 5 0
  ##start
  a0 1 2
  ##end
  a1 9 2
  3 5 4
  </code></pre>
  <p>python file:</p>
  <pre><code>import re
  import pandas as pd
  import networkx as nx
  import matplotlib.pyplot as plt
  
  def file_parsing(file_path):
      cnt = 0
      output_list = []
  
      with open(file_path, 'r') as fp:
          for line in fp:
              cnt += 1
              #checks for the room name and coordinates
              if re.match('([^\s#]{1,10}) (\d+) (\d+)', line, re.MULTILINE):
                  output_list.append(line.strip().split(' '))
              #checks for start
              if line.startswith('##start'):
                  output_list.append(next(fp, '').strip().split())
              #checks for start
              if line.startswith('##end'):
                  output_list.append(next(fp, '').strip().split())
      room_name = [item[0] for item in output_list]
      x_coord = [int(item[1]) for item in output_list]
      y_coord = [int(item[2]) for item in output_list]
      x_y = list(zip(x_coord, y_coord))
      return (room_name, output_list, x_y)
  
  rooms, room_coords, xpos_ypos = file_parsing('ex.txt')
  print(&quot;Room information: &quot;, room_coords)
  print(&quot;X and Y position as tuple list: &quot;, xpos_ypos)
  DG = nx.DiGraph()
  DG.add_nodes_from(rooms, pos = xpos_ypos)
  pos = nx.get_node_attributes(DG, 'pos')
  print(pos)
  
  plt.figure()
  
  nx.draw_networkx(DG)
  </code></pre>
  <p>As you see, I have my <code>xpos_ypos</code> in a zip, which creates a list of tuples. And my order of iteration matters because the first room will have the x and y coordinates from the first tuple.</p>
  <p>For example, my first room is <code>a2a</code> which will have the coordinate of <code>(5, 0)</code>. Room <code>a0</code> will have coordinates if <code>(1, 2)</code>. Now, if I want to do the same thing over and over for each room: how could I add the room coordinates attributes to each room? In my case, I'm getting a dictionary as a result:</p>
  <p><code>{'a2a': [(5, 0), (1, 2), (9, 2), (5, 4)], 'a0': [(5, 0), (1, 2), (9, 2), (5, 4)], 'a1': [(5, 0), (1, 2), (9, 2), (5, 4)], '3': [(5, 0), (1, 2), (9, 2), (5, 4)]}</code></p>
  <p>and this is the output <code>draw_networkx(DG)</code>:
  <img src="https://i.imgur.com/cidjx8l.png" alt="digraph" /></p>