title: Python: how to generate a scale-free network with pre-defined node positions?
body: <p>I want to generate a scale-free network following the <em>Barabasi-Albert</em> algorithm involving <em>growth</em> and <em>preferential attachment</em>.</p>
  
  <p>I use the following script to create the network:</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  n=100 #Number of nodes
  m=4 #Number of initial links
  seed=100
  G=nx.barabasi_albert_graph(n, m, seed)
  nx.draw(G)
  plt.show()
  </code></pre>
  
  <p>This produces the following output:
  <a href="https://i.stack.imgur.com/lfE93.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lfE93.png" alt="enter image description here"></a></p>
  
  <p><strong>I am not happy with how the nodes are positioned.</strong> I want them to be positioned according to a pre-defined scheme which resembles a regular grid, while still maintaining the scale-free features:</p>
  
  <p><a href="https://i.stack.imgur.com/XP0XF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XP0XF.png" alt="enter image description here"></a></p>
  
  <p>I can create a dictionary of positions which reflects my grid:</p>
  
  <pre><code>pos = dict( (n, n) for n in G.nodes() )
  labels = dict( ((i, j), i + (n-1-j) * n ) for i, j in G.nodes() )
  inds=labels.keys()
  vals=labels.values()
  inds.sort()
  vals.sort()
  pos2=dict(zip(vals,inds))
  </code></pre>
  
  <p><strong>My question:</strong> how can I modify the script to obtain a Barabasi-Albert graph with the node positions specified in <code>pos2</code>, which is to say according to my grid?</p>