<h3 dir="auto">Bug summary</h3>
<p dir="auto">The autoscale limits do not work when using <code class="notranslate">mpl.collections.PathCollection</code></p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

fig, axs = plt.subplots(1, 3, figsize=(6, 2))

# One red triangle as a simple path
# In my use case these are parsed from vector graphics
my_path = mpl.path.Path(np.array([[7, 7], [7, 15], [15, 15], [7, 7]]))

# Add same path to all axes
for ax in axs:
    collection = mpl.collections.PathCollection([my_path],
                                                edgecolors='k', 
                                                facecolors='r')
    ax.add_artist(collection)

# Use autoscale in first axes
ax = axs[0]
ax.autoscale()
ax.set_title('ax.autoscale()')

# Use margin in second axes
ax = axs[1]
ax.margins(0.1)
ax.set_title('ax.margins(0.1)')

# Manually set limits in third axes
ax = axs[2]
ax.set_xlim(0, 20)
ax.set_ylim(0, 20)
ax.set_title('ax.set_xlim(0, 20)\nax.set_ylim(0, 20)')

plt.savefig('PathCollection_autoscale_bug.png', facecolor='w', bbox_inches='tight')"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">as</span> <span class="pl-s1">mpl</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-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">axs</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>(<span class="pl-c1">1</span>, <span class="pl-c1">3</span>, <span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-c1">6</span>, <span class="pl-c1">2</span>))

<span class="pl-c"># One red triangle as a simple path</span>
<span class="pl-c"># In my use case these are parsed from vector graphics</span>
<span class="pl-s1">my_path</span> <span class="pl-c1">=</span> <span class="pl-s1">mpl</span>.<span class="pl-s1">path</span>.<span class="pl-v">Path</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">7</span>, <span class="pl-c1">7</span>], [<span class="pl-c1">7</span>, <span class="pl-c1">15</span>], [<span class="pl-c1">15</span>, <span class="pl-c1">15</span>], [<span class="pl-c1">7</span>, <span class="pl-c1">7</span>]]))

<span class="pl-c"># Add same path to all axes</span>
<span class="pl-k">for</span> <span class="pl-s1">ax</span> <span class="pl-c1">in</span> <span class="pl-s1">axs</span>:
    <span class="pl-s1">collection</span> <span class="pl-c1">=</span> <span class="pl-s1">mpl</span>.<span class="pl-s1">collections</span>.<span class="pl-v">PathCollection</span>([<span class="pl-s1">my_path</span>],
                                                <span class="pl-s1">edgecolors</span><span class="pl-c1">=</span><span class="pl-s">'k'</span>, 
                                                <span class="pl-s1">facecolors</span><span class="pl-c1">=</span><span class="pl-s">'r'</span>)
    <span class="pl-s1">ax</span>.<span class="pl-en">add_artist</span>(<span class="pl-s1">collection</span>)

<span class="pl-c"># Use autoscale in first axes</span>
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">axs</span>[<span class="pl-c1">0</span>]
<span class="pl-s1">ax</span>.<span class="pl-en">autoscale</span>()
<span class="pl-s1">ax</span>.<span class="pl-en">set_title</span>(<span class="pl-s">'ax.autoscale()'</span>)

<span class="pl-c"># Use margin in second axes</span>
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">axs</span>[<span class="pl-c1">1</span>]
<span class="pl-s1">ax</span>.<span class="pl-en">margins</span>(<span class="pl-c1">0.1</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">set_title</span>(<span class="pl-s">'ax.margins(0.1)'</span>)

<span class="pl-c"># Manually set limits in third axes</span>
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">axs</span>[<span class="pl-c1">2</span>]
<span class="pl-s1">ax</span>.<span class="pl-en">set_xlim</span>(<span class="pl-c1">0</span>, <span class="pl-c1">20</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">set_ylim</span>(<span class="pl-c1">0</span>, <span class="pl-c1">20</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">set_title</span>(<span class="pl-s">'ax.set_xlim(0, 20)<span class="pl-cce">\n</span>ax.set_ylim(0, 20)'</span>)

<span class="pl-s1">plt</span>.<span class="pl-en">savefig</span>(<span class="pl-s">'PathCollection_autoscale_bug.png'</span>, <span class="pl-s1">facecolor</span><span class="pl-c1">=</span><span class="pl-s">'w'</span>, <span class="pl-s1">bbox_inches</span><span class="pl-c1">=</span><span class="pl-s">'tight'</span>)</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/43403140/227563080-68ab409b-a501-4708-8dfb-0d66b1d82da7.png"><img src="https://user-images.githubusercontent.com/43403140/227563080-68ab409b-a501-4708-8dfb-0d66b1d82da7.png" alt="PathCollection_autoscale_bug" style="max-width: 100%;"></a></p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">The outcome of autoscaling should show the path(s) and automatically update the x and y limits so that the paths are not out of view.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Ubuntu</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.7.1.</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">module://matplotlib_inline.backend_inline</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.11.0</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">None</p>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">When using <a href="http://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" rel="nofollow">axes.annotate</a> to generate an arrow, sometimes, regardless of zorder, the arrow is drawn below the grid. It's expected that with zorder &gt;2.5 it should draw above the grid.</p>
<p dir="auto">This does not happen for all arrows. For the arrows that do have this behavior it is consistent. So for example, on the default settings an arrow from (0.2, 0.2) to (0.8, 0.2) has the expected behavior, but in the reproduction example it does not.</p>
<p dir="auto">This is particularly obvious when the grid is dashed.</p>
<p dir="auto"><strong>Possibly related issues</strong></p>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="105791997" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/5045" data-hovercard-type="issue" data-hovercard-url="/matplotlib/matplotlib/issues/5045/hovercard" href="https://github.com/matplotlib/matplotlib/issues/5045">#5045</a></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
fig, ax = plt.subplots()
ax.set_xlim(-1, 7)
ax.set_ylim(-1, 6)
ax.grid(True, linestyle='dashed')
an = ax.annotate(&quot;&quot;, xy=(2, 1), xytext=(6, 1), arrowprops=dict(arrowstyle=&quot;-&quot;, shrinkA=0, shrinkB=0, color='g', zorder=4))
plt.show()"><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-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">ax</span>.<span class="pl-en">set_xlim</span>(<span class="pl-c1">-</span><span class="pl-c1">1</span>, <span class="pl-c1">7</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">set_ylim</span>(<span class="pl-c1">-</span><span class="pl-c1">1</span>, <span class="pl-c1">6</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">grid</span>(<span class="pl-c1">True</span>, <span class="pl-s1">linestyle</span><span class="pl-c1">=</span><span class="pl-s">'dashed'</span>)
<span class="pl-s1">an</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">annotate</span>(<span class="pl-s">""</span>, <span class="pl-s1">xy</span><span class="pl-c1">=</span>(<span class="pl-c1">2</span>, <span class="pl-c1">1</span>), <span class="pl-s1">xytext</span><span class="pl-c1">=</span>(<span class="pl-c1">6</span>, <span class="pl-c1">1</span>), <span class="pl-s1">arrowprops</span><span class="pl-c1">=</span><span class="pl-en">dict</span>(<span class="pl-s1">arrowstyle</span><span class="pl-c1">=</span><span class="pl-s">"-"</span>, <span class="pl-s1">shrinkA</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">shrinkB</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">'g'</span>, <span class="pl-s1">zorder</span><span class="pl-c1">=</span><span class="pl-c1">4</span>))
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>

<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/931176/30222698-8848f9b8-947c-11e7-9d1c-633fd55160a2.png"><img src="https://user-images.githubusercontent.com/931176/30222698-8848f9b8-947c-11e7-9d1c-633fd55160a2.png" alt="figure_1" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">The line should cover the grid</p>
<p dir="auto"><strong>Working example</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
fig, ax = plt.subplots()
ax.grid(True, linestyle='dashed')
an = ax.annotate(&quot;&quot;, xy=(0.2, 0.2), xytext=(0.8, 0.2), arrowprops=dict(arrowstyle=&quot;-&quot;, shrinkA=0, shrinkB=0, color='g', zorder=4))
plt.show()"><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-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">ax</span>.<span class="pl-en">grid</span>(<span class="pl-c1">True</span>, <span class="pl-s1">linestyle</span><span class="pl-c1">=</span><span class="pl-s">'dashed'</span>)
<span class="pl-s1">an</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">annotate</span>(<span class="pl-s">""</span>, <span class="pl-s1">xy</span><span class="pl-c1">=</span>(<span class="pl-c1">0.2</span>, <span class="pl-c1">0.2</span>), <span class="pl-s1">xytext</span><span class="pl-c1">=</span>(<span class="pl-c1">0.8</span>, <span class="pl-c1">0.2</span>), <span class="pl-s1">arrowprops</span><span class="pl-c1">=</span><span class="pl-en">dict</span>(<span class="pl-s1">arrowstyle</span><span class="pl-c1">=</span><span class="pl-s">"-"</span>, <span class="pl-s1">shrinkA</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">shrinkB</span><span class="pl-c1">=</span><span class="pl-c1">0</span>, <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">'g'</span>, <span class="pl-s1">zorder</span><span class="pl-c1">=</span><span class="pl-c1">4</span>))
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/931176/30222765-d7570c16-947c-11e7-9c0b-523a0fc012ef.png"><img src="https://user-images.githubusercontent.com/931176/30222765-d7570c16-947c-11e7-9c0b-523a0fc012ef.png" alt="figure_2" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Operating System: Windows 10</li>
<li>Matplotlib Version: 2.0.2</li>
<li>Python Version: 3.6.2</li>
</ul>
<p dir="auto">Installed using pip install</p>