title: Renaming a Graph in Networkx
body: <p>I am new on Python and I am trying to learn Networkx ( <a href="https://networkx.github.io/" rel="nofollow noreferrer">https://networkx.github.io/</a>  )</p>
  <p>I am trying to run a basic a code:</p>
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  G=nx.Graph()
  
  G.add_node(1)
  G.add_node(2)
  G.add_node(3)
  G.add_node(4)
  G.add_node(5)
  G.add_node(6)
  G.add_node(7)
  
  G.add_edge(1,2)
  G.add_edge(2,3)
  G.add_edge(3,4)
  G.add_edge(4,5)
  G.add_edge(5,6)
  G.add_edge(6,7)
  G.add_edge(7,1)
  
  G.add_edge(1,3)
  G.add_edge(1,4)
  G.add_edge(1,5)
  G.add_edge(1,6)
  G.add_edge(1,7)
  
  G.add_edge(2,4)
  G.add_edge(2,5)
  G.add_edge(2,6)
  G.add_edge(2,7)
  
  G.add_edge(3,5)
  G.add_edge(3,6)
  G.add_edge(3,7)
  
  G.add_edge(4,6)
  G.add_edge(4,7)
  
  G.add_edge(5,7)
  
  nx.draw(G)
  
  plt.savefig(&quot;graph1.png&quot;)
  plt.show()
  </code></pre>
  <p>and this is the graph generated:</p>
  <p><a href="https://i.stack.imgur.com/O0T7Pm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O0T7Pm.png" alt="enter image description here" /></a></p>
  <p>The problem comes when trying to add names to the nodes. I am running the next code:</p>
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  G=nx.Graph()
  
  G.add_node(1)
  G.add_node(2)
  G.add_node(3)
  G.add_node(4)
  G.add_node(5)
  G.add_node(6)
  G.add_node(7)
  
  G.add_edge(1,2)
  G.add_edge(2,3)
  G.add_edge(3,4)
  G.add_edge(4,5)
  G.add_edge(5,6)
  G.add_edge(6,7)
  G.add_edge(7,1)
  
  G.add_edge(1,3)
  G.add_edge(1,4)
  G.add_edge(1,5)
  G.add_edge(1,6)
  G.add_edge(1,7)
  
  G.add_edge(2,4)
  G.add_edge(2,5)
  G.add_edge(2,6)
  G.add_edge(2,7)
  
  G.add_edge(3,5)
  G.add_edge(3,6)
  G.add_edge(3,7)
  
  G.add_edge(4,6)
  G.add_edge(4,7)
  
  G.add_edge(5,7)
  
  names = {1:&quot;Central&quot;,2:&quot;South&quot;,3:&quot;North&quot;,4:&quot;East&quot;,5:&quot;West&quot;,6:&quot;Up&quot;,7:&quot;Down&quot;}
  H=nx.relabel_nodes(G,names)
  
  nx.draw(H)
  
  plt.savefig(&quot;graph1.png&quot;)
  plt.show()
  </code></pre>
  <p>and the resulted graph is this one:</p>
  <p><a href="https://i.stack.imgur.com/m9JuYm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m9JuYm.png" alt="enter image description here" /></a></p>
  <p>How can I add names to the nodes? I am using python 3.8 and Networkx 2.4</p>