title: How to reshape a networkx graph in Python?
body: <p>So I created a really naive (probably inefficient) way of generating hasse diagrams.   </p>
  
  <p><strong><em>Question:</em></strong></p>
  
  <p>I have 4 dimensions... <strong><code>p</code></strong> <strong><code>q</code></strong> <strong><code>r</code></strong> <strong><code>s</code></strong> .</p>
  
  <p>I want to display it uniformly (tesseract) but I have no idea how to reshape it. <strong>How can one reshape a networkx graph in Python?</strong></p>
  
  <p>I've seen some examples of people using <code>spring_layout()</code> and <code>draw_circular()</code> but it doesn't shape in the way I'm looking for because they aren't uniform.</p>
  
  <p><strong>Is there a way to reshape my graph and make it uniform?</strong> (i.e. reshape my hasse diagram into a tesseract shape (preferably using <code>nx.draw()</code> )</p>
  
  <p>Here's what mine currently look like:
  <img src="https://i.stack.imgur.com/I8qNj.png" alt="enter image description here"></p>
  
  <p>Here's my code to generate the hasse diagram of N dimensions</p>
  
  <pre><code>#!/usr/bin/python
  
  import networkx as nx
  import matplotlib.pyplot as plt
  import itertools
  
  H = nx.DiGraph()
  
  axis_labels = ['p','q','r','s']
  
  D_len_node = {}
  
  #Iterate through axis labels
  for i in xrange(0,len(axis_labels)+1):
      #Create edge from empty set
      if i == 0:
          for ax in axis_labels:
              H.add_edge('O',ax)
      else:
          #Create all non-overlapping combinations
          combinations = [c for c in itertools.combinations(axis_labels,i)]
          D_len_node[i] = combinations
      #Create edge from len(i-1) to len(i) #eg. pq &gt;&gt;&gt; pqr, pq &gt;&gt;&gt; pqs
      if i &gt; 1:
          for node in D_len_node[i]:
              for p_node in D_len_node[i-1]:
                  #if set.intersection(set(p_node),set(node)): Oops
                  if all(p in node for p in p_node) == True: #should be this!
                      H.add_edge(''.join(p_node),''.join(node))
  
  #Show Plot
  nx.draw(H,with_labels = True,node_shape = 'o')
  plt.show() 
  </code></pre>
  
  <p>I want to reshape it like this:
  <img src="https://i.stack.imgur.com/appIm.png" alt="enter image description here"></p>
  
  <p>If anyone knows of an easier way to make Hasse Diagrams, please <strong>share some wisdom</strong> but that's not the main aim of this post.</p>