title: set axis limits in matplotlib pyplot
body: <p>I have two subplots in a figure. I want to set the axes of the second subplot such that it has the same limits as the first subplot (which changes depending on the values plotted). Can someone please help me? Here is the code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  plt.figure(1, figsize = (10, 20))
  ## First subplot: Mean value in each period (mean over replications)
  plt.subplot(211, axisbg = 'w')
  plt.plot(time,meanVector[0:xMax], color = '#340B8C', 
           marker = 'x', ms = 4, mec = '#87051B', markevery = (asp, 
                                                               2*asp))
  plt.xticks(numpy.arange(0, T+1, jump), rotation = -45)
  plt.axhline(y = Results[0], color = '#299967', ls = '--')
  plt.ylabel('Mean Value')
  plt.xlabel('Time')
  plt.grid(True)
  
  
  ## Second subplot: moving average for determining warm-up period
  ## (Welch method)
  plt.subplot(212)    
  plt.plot(time[0:len(yBarWvector)],yBarWvector, color = '#340B8C')
  plt.xticks(numpy.arange(0, T+1, jump), rotation = -45)
  plt.ylabel('yBarW')
  plt.xlabel('Time')
  plt.xlim((0, T))
  plt.grid(True)
  </code></pre>
  
  <p>In the second subplot, what should be the arguments for <code>plt.ylim()</code> function? I tried defining </p>
  
  <pre><code>ymin, ymax = plt.ylim()
  </code></pre>
  
  <p>in the first subplot and then set </p>
  
  <pre><code>plt.ylim((ymin,ymax))
  </code></pre>
  
  <p>in the second subplot. But that did not work, because the returned value <code>ymax</code> is the maximum value taken by the <code>y</code> variable (mean value) in the first subplot and not the upper limit of the y-axis. </p>
  
  <p>Thanks in advance. </p>