title: matplotlib: place axes relative to other axes, with automatic updating
body: <p>Matplotlib has well documented methods of how to place multiple sets of axes in a figure window, but I cannot figure out how to define the position of one set of axes relative to the position of another set of axes.  For example,</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np    
  
  #Define data
  x1 = np.arange(0,10,0.01)
  y1 = np.sqrt(x1)
  x2 = x1
  y2 = 1.0/2.0 * x2**2.0
  
  #Generate vertically stacked plots
  fig = plt.figure()
  ax1 = fig.add_subplot(211)
  ax1.plot(x1,y1)
  ax2 = fig.add_subplot(212)
  ax2.plot(x2,y2)
  fig.savefig('nice_stacked_plots.png')
  </code></pre>
  
  <p>gives the following plot:</p>
  
  <p><img src="https://i.stack.imgur.com/SGgHv.png" alt="nice_stacked_plots"></p>
  
  <p>This is all well and good, but when I change the size of the bottom axes</p>
  
  <pre><code>#Change the size of the bottom plot
  bbox2 = ax2.get_position()
  ax2.set_position([bbox2.x0, bbox2.y0, bbox2.width, bbox2.height * 1.25])
  ax2.set_ylim(0,60)
  fig.savefig('overlapping_stacked_plots.png')
  </code></pre>
  
  <p>the bottom axes overlap with the top axes</p>
  
  <p><img src="https://i.stack.imgur.com/4Q1DH.png" alt="overlapping_stacked_plots"></p>
  
  <p>I realize I could subsequently update the position of the top axes to remove the overlap, but I would like to just specify the top axes position relative to the bottom axes at the outset, and have things automatically update.  </p>
  
  <p>For example, in the <a href="http://matplotlib.org/users/annotations_guide.html" rel="nofollow noreferrer">annotate tutorial</a> it is possible to place an annotation and then place a 2nd annotation at a specified offset from the 1st annotation using the <code>OffsetFrom</code> class.  If the 1st annotation moves, then the 2nd annotation moves with it.  I would like to do something similar with axes.</p>