title: Matplotlib y-axis limits not updating after setting x-axis limits?
body: <p>I'm trying to plot a subset of some data, but the y-axis limits are not updated properly after I set the x-axis limits. Is there a way to have matplotlib update the y-axis limits after setting the x-axis limits?</p>
  
  <p>For example, consider the following plot:</p>
  
  <pre><code>import numpy
  import pylab
  pylab.plot(numpy.arange(100)**2.0)
  </code></pre>
  
  <p>which gives: <img src="https://i.stack.imgur.com/3okr6.png" alt="Plot 1 full range"></p>
  
  <p>which works fine. However if I want to only view the part from x=0 to x=10, the y-scaling is messed up:</p>
  
  <pre><code>pylab.plot(numpy.arange(100)**2.0)
  pylab.xlim(0,10)
  </code></pre>
  
  <p>which gives: <img src="https://i.stack.imgur.com/8AoMZ.png" alt="Plot 1 subset">.</p>
  
  <p>In the former case, the x- and y-axis are scaled properly, in the latter case, the y-axis is still scaled the same, even if the data is not plotted. How do I tell matplotlib to update the y-axis scaling?</p>
  
  <p>Obvious workarounds would be to plot a subset of the data itself, or to reset the y-axis limits manually by inspecting the data, but those are both rather cumbersome.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>The example above is simplified, in the more general case one has:</p>
  
  <pre><code>pylab.plot(xdata, ydata1)
  pylab.plot(xdata, ydata2)
  pylab.plot(xdata, ydata3)
  pylab.xlim(xmin, xmax)
  </code></pre>
  
  <p>Setting the y-axis range manually is of course possible</p>
  
  <pre><code>subidx = N.argwhere((xdata &gt;= xmin) &amp; (xdata &lt;= xmax))
  ymin = N.min(ydata1[subidx], ydata2[subidx], ydata3[subidx])
  ymax = N.max(ydata1[subidx], ydata2[subidx], ydata3[subidx])
  pylab.xlim(xmin, xmax)
  </code></pre>
  
  <p>but this is cumbersome to say the least (imho). Is there a faster way to do this without manually calculating the plotranges? Thanks!</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>The function <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.autoscale" rel="noreferrer">autoscale</a> does some scaling and seems the right candidate for this job, but treats the axes independently and <em>only</em> scales to the full data range, no matter what the axes limits are.</p>