title: Formatting multiple subgraphs - pydot
body: <p>I am new to pydot which I would use to create a graph. I would like to format the nodes so as to have blocks of nodes in the same line. I accomplished that using subgraphs, and settings the rank to be the same.</p>
  
  <pre><code>import pydot
  
  # define a graph
  graph = pydot.Dot(graph_type="digraph")
  
  # define nodes
  node_rec = pydot.Node(label = "Start",shape = "box")
  node_bs = pydot.Node("bs")
  node_man = pydot.Node("man")
  node_dec = pydot.Node("dec")
  node_ms = pydot.Node("ms")
  node_gtp = pydot.Node("gtp")
  node_des = pydot.Node("End",shape = "box")
  
  # add nodes
  graph.add_node(node_rec)
  graph.add_node(node_man)
  graph.add_node(node_gtp)
  graph.add_node(node_des)
  
  # add edges
  graph.add_edge(pydot.Edge(node_rec, node_bs))
  graph.add_edge(pydot.Edge(node_rec, node_man))
  graph.add_edge(pydot.Edge(node_bs, node_dec))
  graph.add_edge(pydot.Edge(node_dec, node_ms))
  graph.add_edge(pydot.Edge(node_ms, node_gtp))
  graph.add_edge(pydot.Edge(node_gtp, node_man))
  graph.add_edge(pydot.Edge(node_man, node_des))
  
  # create a subgraph
  layer1 = pydot.Subgraph(rank='same')
  layer1.add_node(node_bs)
  layer1.add_node(node_dec)
  layer1.add_node(node_ms)
  graph.add_subgraph(layer1)
  
  # create figure
  graph.write_png('output_ok.png')
  </code></pre>
  
  <p>However, if I want to have two subgraphs, one on top of each other, I fail to grasp what would be the proper code. Here an example that uses the same nodes, builds two subgraphs with different ranks, and yet it fails.</p>
  
  <pre><code># add nodes
  graph.add_node(node_rec)
  graph.add_node(node_des)
  
  # add edges
  graph.add_edge(pydot.Edge(node_rec, node_bs))
  graph.add_edge(pydot.Edge(node_rec, node_man))
  graph.add_edge(pydot.Edge(node_bs, node_dec))
  graph.add_edge(pydot.Edge(node_dec, node_ms))
  graph.add_edge(pydot.Edge(node_ms, node_gtp))
  graph.add_edge(pydot.Edge(node_gtp, node_man))
  graph.add_edge(pydot.Edge(node_man, node_des))
  
  layer1 = pydot.Subgraph(rank='source')
  layer1.add_node(node_bs)
  layer1.add_node(node_dec)
  layer1.add_node(node_ms)
  
  graph.add_subgraph(layer1)
  
  layer2 = pydot.Subgraph(rank='max')
  layer2.add_node(node_man)
  layer2.add_node(node_gtp)
  
  graph.add_subgraph(layer2)
  
  # create figure
  graph.write_png('output_bad2.png')
  </code></pre>
  
  <p>Any idea where I am getting this wrong? </p>