Plotting networkx graph: node labels adjacent to nodes?
<p>I am trying to plot association rules and am having a difficult time getting the node labels below to "follow" the nodes. That is, I would like each label to automatically be near its respective node without having to hard-code any values. The output from below doesn't even include some of the node labels. How can I make these labels dynamically follow the nodes?</p>

<pre><code>import pandas as pd
import networkx as nx
import matlotlib.pyplot as plt    

df = pd.DataFrame({'node1': ['candy', 'cookie', 'beach', 'mark', 'black'],
                   'node2': ['beach', 'beach', 'cookie', 'beach', 'mark'], 
                   'weight': [10, 5, 3, 4, 20]})

G = nx.Graph()

for idx in df.index:
    node1 = df.loc[idx, 'node1']
    node2 = df.loc[idx, 'node2']
    weight = df.loc[idx, 'weight']
    G.add_edge(node1, node2, weight = weight)

nx.draw(G, node_size = 100)

pos = nx.spring_layout(G)

nx.draw_networkx_labels(G, pos = pos, font_size = 14, with_labels = True)

plt.draw()
plt.show()
</code></pre>

<p><a href="https://i.stack.imgur.com/r8011.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r8011.png" alt="enter image description here"></a></p>