title: How to store graph as an networkx.classes.graph.Graph object?
body: <p>I am quite new to <code>Networkx</code>, so I am experimenting with its various graphing functions and would like to store the generated graph as an <code>networkx.classes.graph.Graph</code> object for further processing, something in the format of <code>&lt;networkx.classes.graph.Graph at xxxxxxxxxxxxxx&gt;</code> as appears on Python output.</p>
  
  <p>Suppose I am using this following code to generate a bipartite graph:</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  G1 = nx.Graph()
  
  G1.add_edges_from([('Frida','The Shawshank Redemption'), ('Pablo','The Shawshank Redemption'), ('Vincent','The Shawshank Redemption'), ('Joan', 'Forrest Gump'), ('Lee', 'Forrest Gump'), ('Andy', 'The Matrix'), ('Frida', 'The Matrix'), ('Pablo', 'The Matrix'),
  ('Andy', 'Anaconda'), ('Claude', 'Anaconda'), ('Georgia', 'Anaconda'), ('Frida', 'The Social Network'), ('Vincent', 'The Social Network'),
  ('Vincent', 'The Godfather'), ('Claude', 'Monty Python and the Holy Grail'), ('Georgia', 'Monty Python and the Holy Grail'), ('Claude', 'Snakes on a Plane'), ('Georgia', 'Snakes on a Plane'),
  ('Joan', 'Kung Fu Panda'), ('Lee', 'Kung Fu Panda'), ('Pablo', 'The Dark Knight'), 
  ('Andy', 'Mean Girls'), ('Joan', 'Mean Girls'), ('Lee', 'Mean Girls')])
  
  l, r = nx.bipartite.sets(G1)
  pos = {}
  
  # Update position for node from each group
  pos.update((node, (1, index)) for index, node in enumerate(l))
  pos.update((node, (2, index)) for index, node in enumerate(r))
  
  nx.draw(G1, pos=pos, with_labels=True)
  plt.show()
  </code></pre>
  
  <p>The last two lines of code will generate this graph:
  <a href="https://i.stack.imgur.com/n80nH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n80nH.png" alt="enter image description here"></a></p>
  
  <p>This, however, is not a <code>networkx.classes.graph.Graph</code> object.</p>
  
  <p>How can I save my graphing output as an <code>networkx.classes.graph.Graph</code> object, so that Python can read this object as such (and be able to retrieve the number of nodes and edges as well as other attributes from such object)?</p>
  
  <p>Thank you.</p>