<p dir="auto">I've run into an issue where creating a RectangleSelector prevents ax.axis('tight') from working properly.  I've discovered that when the selector is created, it creates new line objects near coordinate (0,0) on the plot.  Though not visible, the axis('tight') respects their presence and will not collapse around the real data.  This matters if the real data is far from the origin.  This seems like a bug?</p>
<p dir="auto">I could work around it if I could figure out how to set the initial location of the RS line objects.</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">RectangleSelector:</p>
<ol dir="auto">
<li>Modifies <code class="notranslate">dataLim</code></li>
<li>This modification seemingly cannot be reverted by removing the patch, or by modifying the patch properties</li>
</ol>
<p dir="auto">Basically I want to be able to use RectangleSelector without it modifying <code class="notranslate">ax.dataLim</code>, because if it does it messes up <code class="notranslate">autoscale</code>.</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 matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.widgets import RectangleSelector

fig, ax = plt.subplots()
lim = ax.dataLim
ax.plot([-0.1, 0.1], [-0.1, 0.1])
assert lim.x0 == lim.y0 == -0.1
assert lim.width == lim.height == 0.2
for kind in ('rect', 'rs'):
    if kind == 'rect':
        rect = Rectangle((0, 0), 0, 1)
        ax.add_patch(rect)
    else:
        rs = RectangleSelector(ax, lambda x: None)
        rect = rs.to_draw
    assert isinstance(rect, Rectangle)
    ax.relim()
    assert lim.x0 == lim.y0 == -0.1
    assert lim.width == 0.2
    assert lim.height == 1.1
    ax.patches.remove(rect)
    assert ax.patches == []
    ax.relim()
    assert lim.height == 0.2, (kind, lim.height)"><pre class="notranslate"><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-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">patches</span> <span class="pl-k">import</span> <span class="pl-v">Rectangle</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">widgets</span> <span class="pl-k">import</span> <span class="pl-v">RectangleSelector</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()
<span class="pl-s1">lim</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-s1">dataLim</span>
<span class="pl-s1">ax</span>.<span class="pl-en">plot</span>([<span class="pl-c1">-</span><span class="pl-c1">0.1</span>, <span class="pl-c1">0.1</span>], [<span class="pl-c1">-</span><span class="pl-c1">0.1</span>, <span class="pl-c1">0.1</span>])
<span class="pl-k">assert</span> <span class="pl-s1">lim</span>.<span class="pl-s1">x0</span> <span class="pl-c1">==</span> <span class="pl-s1">lim</span>.<span class="pl-s1">y0</span> <span class="pl-c1">==</span> <span class="pl-c1">-</span><span class="pl-c1">0.1</span>
<span class="pl-k">assert</span> <span class="pl-s1">lim</span>.<span class="pl-s1">width</span> <span class="pl-c1">==</span> <span class="pl-s1">lim</span>.<span class="pl-s1">height</span> <span class="pl-c1">==</span> <span class="pl-c1">0.2</span>
<span class="pl-k">for</span> <span class="pl-s1">kind</span> <span class="pl-c1">in</span> (<span class="pl-s">'rect'</span>, <span class="pl-s">'rs'</span>):
    <span class="pl-k">if</span> <span class="pl-s1">kind</span> <span class="pl-c1">==</span> <span class="pl-s">'rect'</span>:
        <span class="pl-s1">rect</span> <span class="pl-c1">=</span> <span class="pl-v">Rectangle</span>((<span class="pl-c1">0</span>, <span class="pl-c1">0</span>), <span class="pl-c1">0</span>, <span class="pl-c1">1</span>)
        <span class="pl-s1">ax</span>.<span class="pl-en">add_patch</span>(<span class="pl-s1">rect</span>)
    <span class="pl-k">else</span>:
        <span class="pl-s1">rs</span> <span class="pl-c1">=</span> <span class="pl-v">RectangleSelector</span>(<span class="pl-s1">ax</span>, <span class="pl-k">lambda</span> <span class="pl-s1">x</span>: <span class="pl-c1">None</span>)
        <span class="pl-s1">rect</span> <span class="pl-c1">=</span> <span class="pl-s1">rs</span>.<span class="pl-s1">to_draw</span>
    <span class="pl-k">assert</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">rect</span>, <span class="pl-v">Rectangle</span>)
    <span class="pl-s1">ax</span>.<span class="pl-en">relim</span>()
    <span class="pl-k">assert</span> <span class="pl-s1">lim</span>.<span class="pl-s1">x0</span> <span class="pl-c1">==</span> <span class="pl-s1">lim</span>.<span class="pl-s1">y0</span> <span class="pl-c1">==</span> <span class="pl-c1">-</span><span class="pl-c1">0.1</span>
    <span class="pl-k">assert</span> <span class="pl-s1">lim</span>.<span class="pl-s1">width</span> <span class="pl-c1">==</span> <span class="pl-c1">0.2</span>
    <span class="pl-k">assert</span> <span class="pl-s1">lim</span>.<span class="pl-s1">height</span> <span class="pl-c1">==</span> <span class="pl-c1">1.1</span>
    <span class="pl-s1">ax</span>.<span class="pl-s1">patches</span>.<span class="pl-en">remove</span>(<span class="pl-s1">rect</span>)
    <span class="pl-k">assert</span> <span class="pl-s1">ax</span>.<span class="pl-s1">patches</span> <span class="pl-c1">==</span> []
    <span class="pl-s1">ax</span>.<span class="pl-en">relim</span>()
    <span class="pl-k">assert</span> <span class="pl-s1">lim</span>.<span class="pl-s1">height</span> <span class="pl-c1">==</span> <span class="pl-c1">0.2</span>, (<span class="pl-s1">kind</span>, <span class="pl-s1">lim</span>.<span class="pl-s1">height</span>)</pre></div>
<p dir="auto">The plain "Rectangle" version passes, but the "RectangleSelector" version does not:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    assert lim.height == 0.2, (kind, lim.height)
AssertionError: ('rs', 1.1)"><pre class="notranslate"><code class="notranslate">    assert lim.height == 0.2, (kind, lim.height)
AssertionError: ('rs', 1.1)
</code></pre></div>
<p dir="auto">And the resulting plot is "stuck" with a minimum autolim y max of 1. I also tried setting properties of the Rectangle patch that's part of the RectangleSelector (xy, width, height) and calling <code class="notranslate">ax.relim()</code> but the bound of <code class="notranslate">1.</code> never decreases.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: Linux x86_64</li>
<li>Matplotlib version: latest <code class="notranslate">master</code></li>
<li>Matplotlib backend: Qt5Agg</li>
<li>Python version: 3.8</li>
</ul>