<h3 dir="auto">Bug report (or feature request)</h3>
<p dir="auto"><strong>Summary</strong></p>

<p dir="auto">In <code class="notranslate">matplotlib</code>, when manually restricting <code class="notranslate">xlim</code>, <code class="notranslate">ylim</code> does not change accordingly.</p>
<p dir="auto"><strong>Code for reproduction</strong></p>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import matplotlib.pyplot as plt

x = np.array([1,2,3,4,5,6,7])
y = x

fig = plt.figure()
ax = plt.axes()
ax.plot(x, y)
print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))

fig = plt.figure()
ax = plt.axes()
ax.plot(x, y)
ax.set_xlim(1, 2)
print('xlim: %s, ylim: %s' % (ax.get_xlim(), ax.get_ylim()))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>,<span class="pl-c1">6</span>,<span class="pl-c1">7</span>])
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">x</span>

<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>()
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">axes</span>()
<span class="pl-s1">ax</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>)
<span class="pl-en">print</span>(<span class="pl-s">'xlim: %s, ylim: %s'</span> <span class="pl-c1">%</span> (<span class="pl-s1">ax</span>.<span class="pl-en">get_xlim</span>(), <span class="pl-s1">ax</span>.<span class="pl-en">get_ylim</span>()))

<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>()
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">axes</span>()
<span class="pl-s1">ax</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">set_xlim</span>(<span class="pl-c1">1</span>, <span class="pl-c1">2</span>)
<span class="pl-en">print</span>(<span class="pl-s">'xlim: %s, ylim: %s'</span> <span class="pl-c1">%</span> (<span class="pl-s1">ax</span>.<span class="pl-en">get_xlim</span>(), <span class="pl-s1">ax</span>.<span class="pl-en">get_ylim</span>()))</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="xlim: (0.7, 7.3), ylim: (0.7, 7.3)
xlim: (1.0, 2.0), ylim: (0.7, 7.3)"><pre class="notranslate"><code class="notranslate">xlim: (0.7, 7.3), ylim: (0.7, 7.3)
xlim: (1.0, 2.0), ylim: (0.7, 7.3)
</code></pre></div>
<p dir="auto"><strong>Expected outcome</strong></p>


<p dir="auto">When I change xlim to (1, 2), I expect ylim to change accordingly (because y's value range becomes [1, 2], now that x's range shrinks), but ylim still remains (0.7, 7.3). In fact, in MATLAB xlim and ylim can coordinate with each other.</p>
<p dir="auto">MATLAB codes to reproduce this behavior:</p>
<div class="highlight highlight-source-matlab notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="x = [1,2,3,4,5,6,7];
y = x;
figure; plot(x, y); disp(ylim);
figure; plot(x, y); xlim([1, 2]); disp(ylim);"><pre class="notranslate">x <span class="pl-k">=</span> [<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>,<span class="pl-c1">4</span>,<span class="pl-c1">5</span>,<span class="pl-c1">6</span>,<span class="pl-c1">7</span>];
y <span class="pl-k">=</span> <span class="pl-smi">x</span>;
<span class="pl-smi">figure</span>; <span class="pl-en">plot</span>(<span class="pl-smi">x</span>, <span class="pl-smi">y</span>); <span class="pl-en">disp</span>(<span class="pl-smi">ylim</span>);
<span class="pl-smi">figure</span>; <span class="pl-en">plot</span>(<span class="pl-smi">x</span>, <span class="pl-smi">y</span>); <span class="pl-en">xlim</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</span>]); <span class="pl-en">disp</span>(<span class="pl-smi">ylim</span>);</pre></div>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: Windows 10</li>
<li>Matplotlib version: 2.2.2</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): <code class="notranslate">module://ipykernel.pylab.backend_inline</code></li>
<li>Python version: 3.6.6</li>
<li>Jupyter version (if applicable): N/A</li>
<li>Other libraries: N/A</li>
</ul>
<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>