title: Python - Add residuals to subplots generated by a for loop
body: <p>I just can't get the subplots to work when adding the residuals with <code>add_axes</code>. It works well without residuals and I can add residuals to just one plot. This is an example of what I'm doing:</p>
  
  <p>First, just to give you an idea of what I'm ploting, (t, y) is the data I want to plot, fit is the fit to the data, and diff is the difference between fit and data.</p>
  
  <pre><code>t, s, fit = [], [], []
  diff = []
  for i in range(12):
      t.append(x / y[i])
  
      s.append(np.linspace(0, 1, num=100, endpoint=True))
      fit.append(UnivariateSpline(t[i], y, er, s=5e20))
      diff.append(fit[i](t[i]) - y)
  </code></pre>
  
  <p>And this is the figure:</p>
  
  <pre><code>fig = plt.figure()
  for i in range(12):
      plt.subplot(4,3,i+1)
      fig.add_axes((0.,0.3,0.7,0.9))
      plt.plot(s[i], fit[i](s[i]), 'r-') # this is the fit
      plt.errorbar(t[i], y, er, fmt='.k',ms=6) # this is the data 
      plt.axis([0,1, 190, 360])
  
      fig.add_axes((0.,0.,0.7,0.3))       
      plot(t[i],diff[i],'or') # this are the residuals
      plt.axis([0,1, 190, 360])
  </code></pre>
  
  <p>So as you can see I'm generating 12 subplots, which works just fine until I add the <code>fig.add_axes</code> to separate each subplot between data+fit and the residuals, but what I get is one messy plot on top of the subplots (figure has been shrunken to see the subplots under):</p>
  
  <p><a href="https://i.stack.imgur.com/Himod.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Himod.png" alt="messy plot"></a></p>
  
  <p>And what I want is 12 subplots where each one looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/mvOc9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mvOc9.png" alt="correct plot"></a></p>