title: labeling networkx node attributes outside of nodes
body: <p>I am working on a small example node set belonging to two types <code>{'human', 'machine'}</code> and I want to label node attributes in dictionary form outside of each node in <code>networkx</code> graph, such as those shown in nodes c, e, j in the graph below. (I used MS Word to add dictionary-type attributes on the graph.):</p>
  
  <p><a href="https://i.stack.imgur.com/uJn1I.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/uJn1I.jpg" alt="enter image description here"></a> </p>
  
  <p>The base plot is generated using the following code:</p>
  
  <pre><code>import networkx as nx
  G = nx.Graph()
  G.add_nodes_from(['a', 'b', 'c', 'd', 'e', 'f', 'g'], type = 'machine')
  G.add_nodes_from(['h', 'i', 'j'], type = 'human')
  G.add_edges_from([('a', 'c'), ('a', 'b'), ('a', 'd'), ('a', 'f'), ('b', 'd'), ('b', 'e'), ('b', 'g'), ('c', 'f'), ('c', 'd'), ('d', 'f'), ('d', 'e'), ('d', 'g'), ('e', 'g'), ('f', 'g'), ('f', 'h'), ('g', 'h'), ('h', 'i'), ('i', 'j')])
  
  def plot_graph(G, weight_name=None):
      import matplotlib.pyplot as plt
  
      plt.figure()
      pos = nx.spring_layout(G)
      edges = G.edges()
      weights = None
  
      if weight_name:
          weights = [int(G[u][v][weight_name]) for u,v in edges]
          labels = nx.get_edge_attributes(G,weight_name)
          nx.draw_networkx_edge_labels(G,pos,edge_labels=labels)
          nx.draw_networkx(G, pos, edges=edges, width=weights);
      else:
          nx.draw_networkx(G, pos, edges=edges);
  
  plot_graph(G, weight_name=None)
  plt.savefig('example.png')
  plt.show()
  </code></pre>
  
  <p>But here is the problem, </p>
  
  <p>the <code>nx.get_node_attributes()</code> and <code>nx.draw_networkx_labels()</code> functions will not include dictionary keys (in this example, 'type') on the labels (this works only for nx.get_edge_attributes() and nx.draw_networkx_edge_labels()), and if one would to use <code>nx.get_node_attributes()</code> and <code>nx.draw_networkx_labels()</code>, original node names will be replaced by attribute values.</p>
  
  <p>I am wondering if there're alternative methods to label attribute in dictionary format outside each node while keeping node names inside the nodes? How should I modify my current code?</p>