<h3 dir="auto">Problem</h3>
<p dir="auto">I'm trying to create a plot which "zooms in" on a subset of a large dataset (I am plotting the entire dataset because it's much more convenient than clipping the underlying dataset). I can do this pretty easily for the x-axis with ax.set_xlim(), because I know what the x-limits of my data should be. However, I don't know what the y-limits should be, and I can't use ax.set_ymargin() because it computes the y-margin for the <em>entire</em> dataset, not the zoomed portion of the dataset. I don't know ahead of time what the min/max values of my dataset will be, so I'm stuck.</p>
<h3 dir="auto">Proposed Solution</h3>
<p dir="auto">Add an option to ax.set_ymargin specifying a subset of the x-data range over which to apply the margin. For example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ax.set_ymargin(0.1, xlim=(0, 1))"><pre class="notranslate"><code class="notranslate">ax.set_ymargin(0.1, xlim=(0, 1))
</code></pre></div>
<p dir="auto">would "zoom in" in y on the portion of the data that exists in the x-range [0, 1], and apply a 10% margin to the data that exists over that range.</p>
<p dir="auto">I filed a matplotlib bug report via GitHub: When x-axis limits are overridden via <code class="notranslate">pyplot.xlim</code>, the default y-axis limits may no longer be sensible.  If limits are overridden for one axis, new limits should be calculated for the remaining axes.  The image at the following URL demonstrates the problem:</p>
<p dir="auto"><a href="http://phillipmfeldman.org/Python/axis_scaling_bug.png" rel="nofollow">http://phillipmfeldman.org/Python/axis_scaling_bug.png</a></p>
<p dir="auto">Phillip</p>