title: in NetworkX cannot save a graph as jpg or png file
body: <p>I have a graph in NetworkX containing some info. After the graph is shown, I want to save it as <code>jpg</code> or <code>png</code> file. I used the <code>matplotlib</code> function <code>savefig</code> but when the image is saved, it does not contain anything. It is just a white image.</p>
  <p>Here is a sample code I wrote:</p>
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  fig = plt.figure(figsize=(12,12))
  ax = plt.subplot(111)
  ax.set_title('Graph - Shapes', fontsize=10)
  
  G = nx.DiGraph()
  G.add_node('shape1', level=1)
  G.add_node('shape2', level=2)
  G.add_node('shape3', level=2)
  G.add_node('shape4', level=3)
  G.add_edge('shape1', 'shape2')
  G.add_edge('shape1', 'shape3')
  G.add_edge('shape3', 'shape4')
  pos = nx.spring_layout(G)
  nx.draw(G, pos, node_size=1500, node_color='yellow', font_size=8, font_weight='bold')
  
  plt.tight_layout()
  plt.show()
  plt.savefig(&quot;Graph.png&quot;, format=&quot;PNG&quot;)
  </code></pre>
  <p>Why is the image saved without anything inside (just white) ?</p>
  <p>This is the image saved (just blank):
  <img src="https://i.stack.imgur.com/hQRoD.png" alt="enter image description here" /></p>