<h3 dir="auto">Bug summary</h3>
<p dir="auto">The contour label (clabel) manual mode fails place any labels. When I click the plot I get an error:<br>
'QuadContourSet' object has no attribute 'ax'<br>
and no labels are added.<br>
I put the Contour Label Demo as an example with clabel option manual=True, but this has happened with different scripts.</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 numpy as np
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt


delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
Z = (Z1 - Z2) * 2
# This custom formatter removes trailing zeros, e.g. &quot;1.0&quot; becomes &quot;1&quot;, and
# then adds a percent sign.
def fmt(x):
    s = f&quot;{x:.1f}&quot;
    if s.endswith(&quot;0&quot;):
        s = f&quot;{x:.0f}&quot;
    return rf&quot;{s} \%&quot; if plt.rcParams[&quot;text.usetex&quot;] else f&quot;{s} %&quot;


# Basic contour plot
fig, ax = plt.subplots()
CS = ax.contour(X, Y, Z)

ax.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10, manual=True)

plt.show()"><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">ticker</span> <span class="pl-k">as</span> <span class="pl-s1">ticker</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">delta</span> <span class="pl-c1">=</span> <span class="pl-c1">0.025</span>
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">-</span><span class="pl-c1">3.0</span>, <span class="pl-c1">3.0</span>, <span class="pl-s1">delta</span>)
<span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">-</span><span class="pl-c1">2.0</span>, <span class="pl-c1">2.0</span>, <span class="pl-s1">delta</span>)
<span class="pl-v">X</span>, <span class="pl-v">Y</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">meshgrid</span>(<span class="pl-s1">x</span>, <span class="pl-s1">y</span>)
<span class="pl-v">Z1</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">exp</span>(<span class="pl-c1">-</span><span class="pl-v">X</span><span class="pl-c1">**</span><span class="pl-c1">2</span> <span class="pl-c1">-</span> <span class="pl-v">Y</span><span class="pl-c1">**</span><span class="pl-c1">2</span>)
<span class="pl-v">Z2</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">exp</span>(<span class="pl-c1">-</span>(<span class="pl-v">X</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>)<span class="pl-c1">**</span><span class="pl-c1">2</span> <span class="pl-c1">-</span> (<span class="pl-v">Y</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>)<span class="pl-c1">**</span><span class="pl-c1">2</span>)
<span class="pl-v">Z</span> <span class="pl-c1">=</span> (<span class="pl-v">Z1</span> <span class="pl-c1">-</span> <span class="pl-v">Z2</span>) <span class="pl-c1">*</span> <span class="pl-c1">2</span>
<span class="pl-c"># This custom formatter removes trailing zeros, e.g. "1.0" becomes "1", and</span>
<span class="pl-c"># then adds a percent sign.</span>
<span class="pl-k">def</span> <span class="pl-en">fmt</span>(<span class="pl-s1">x</span>):
    <span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s">f"<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">x</span>:.1f<span class="pl-kos">}</span></span>"</span>
    <span class="pl-k">if</span> <span class="pl-s1">s</span>.<span class="pl-en">endswith</span>(<span class="pl-s">"0"</span>):
        <span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s">f"<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">x</span>:.0f<span class="pl-kos">}</span></span>"</span>
    <span class="pl-k">return</span> <span class="pl-s">rf"<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">s</span><span class="pl-kos">}</span></span> \%"</span> <span class="pl-k">if</span> <span class="pl-s1">plt</span>.<span class="pl-s1">rcParams</span>[<span class="pl-s">"text.usetex"</span>] <span class="pl-k">else</span> <span class="pl-s">f"<span class="pl-s1"><span class="pl-kos">{</span><span class="pl-s1">s</span><span class="pl-kos">}</span></span> %"</span>


<span class="pl-c"># Basic contour plot</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-v">CS</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">contour</span>(<span class="pl-v">X</span>, <span class="pl-v">Y</span>, <span class="pl-v">Z</span>)

<span class="pl-s1">ax</span>.<span class="pl-en">clabel</span>(<span class="pl-v">CS</span>, <span class="pl-v">CS</span>.<span class="pl-s1">levels</span>, <span class="pl-s1">inline</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">fmt</span><span class="pl-c1">=</span><span class="pl-s1">fmt</span>, <span class="pl-s1">fontsize</span><span class="pl-c1">=</span><span class="pl-c1">10</span>, <span class="pl-s1">manual</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-s1">plt</span>.<span class="pl-en">show</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/102812332/161284744-7b4368e0-bcd5-462c-a26d-a4fd496bc40f.png"><img src="https://user-images.githubusercontent.com/102812332/161284744-7b4368e0-bcd5-462c-a26d-a4fd496bc40f.png" alt="contour" style="max-width: 100%;"></a><br>
I get the following error:<br>
Traceback (most recent call last):<br>
File "/Users/azahel/anaconda3/lib/python3.9/site-packages/matplotlib/cbook/<strong>init</strong>.py", line 287, in process<br>
func(*args, **kwargs)<br>
File "/Users/azahel/anaconda3/lib/python3.9/site-packages/matplotlib/contour.py", line 70, in _contour_labeler_event_handler<br>
if event.inaxes == cs.ax:<br>
AttributeError: 'QuadContourSet' object has no attribute 'ax'</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/102812332/161284456-3f4a173b-fa16-44e6-8e36-f314154a46b6.png"><img src="https://user-images.githubusercontent.com/102812332/161284456-3f4a173b-fa16-44e6-8e36-f314154a46b6.png" alt="image" style="max-width: 100%;"></a></p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">I recently upgraded matplotlib to 3.5.1, I'm not sure if this was a problem with previous versions.<br>
Checking the file contour.py it is clear that ContourSet, and by extension QuadContourSet, do not have the attribute "ax" but rather "axes".<br>
Changing line 70 from contour.py<br>
"        if event.inaxes == cs.ax:"<br>
to<br>
"        if event.inaxes == cs.axes:"<br>
resolves the issue.<br>
Seeing in the documentation that Contour set is described to have the attribute "ax", perhaps the real fix would be to change ContourSet class.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">OS/X</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.1</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">MacOSX</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.9.12</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">conda</p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">I used to be able to use a legend picker as described in this <a href="https://matplotlib.org/stable/gallery/event_handling/legend_picking.html" rel="nofollow">matplotlib tutorial</a>.<br>
It doesn't work anymore. I bet it was an up</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 numpy as np
import matplotlib.pyplot as plt


t = np.linspace(0, 1)
y1 = 2 * np.sin(2*np.pi*t)
y2 = 4 * np.sin(2*np.pi*2*t)

fig, ax = plt.subplots()
ax.set_title('Click on legend line to toggle line on/off')
line1, = ax.plot(t, y1, lw=2, label='1 Hz')
line2, = ax.plot(t, y2, lw=2, label='2 Hz')
leg = ax.legend(fancybox=True, shadow=True)

lines = [line1, line2]
lined = {}  # Will map legend lines to original lines.
for legline, origline in zip(leg.get_lines(), lines):
    legline.set_picker(True)  # Enable picking on the legend line.
    lined[legline] = origline


def on_pick(event):
    # On the pick event, find the original line corresponding to the legend
    # proxy line, and toggle its visibility.
    legline = event.artist
    origline = lined[legline]
    visible = not origline.get_visible()
    origline.set_visible(visible)
    # Change the alpha on the line in the legend so we can see what lines
    # have been toggled.
    legline.set_alpha(1.0 if visible else 0.2)
    fig.canvas.draw()

fig.canvas.mpl_connect('pick_event', on_pick)
plt.show()"><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">t</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">0</span>, <span class="pl-c1">1</span>)
<span class="pl-s1">y1</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span> <span class="pl-c1">*</span> <span class="pl-s1">np</span>.<span class="pl-en">sin</span>(<span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span><span class="pl-c1">*</span><span class="pl-s1">t</span>)
<span class="pl-s1">y2</span> <span class="pl-c1">=</span> <span class="pl-c1">4</span> <span class="pl-c1">*</span> <span class="pl-s1">np</span>.<span class="pl-en">sin</span>(<span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span><span class="pl-c1">*</span><span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">t</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_title</span>(<span class="pl-s">'Click on legend line to toggle line on/off'</span>)
<span class="pl-s1">line1</span>, <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">plot</span>(<span class="pl-s1">t</span>, <span class="pl-s1">y1</span>, <span class="pl-s1">lw</span><span class="pl-c1">=</span><span class="pl-c1">2</span>, <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'1 Hz'</span>)
<span class="pl-s1">line2</span>, <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">plot</span>(<span class="pl-s1">t</span>, <span class="pl-s1">y2</span>, <span class="pl-s1">lw</span><span class="pl-c1">=</span><span class="pl-c1">2</span>, <span class="pl-s1">label</span><span class="pl-c1">=</span><span class="pl-s">'2 Hz'</span>)
<span class="pl-s1">leg</span> <span class="pl-c1">=</span> <span class="pl-s1">ax</span>.<span class="pl-en">legend</span>(<span class="pl-s1">fancybox</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">shadow</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-s1">lines</span> <span class="pl-c1">=</span> [<span class="pl-s1">line1</span>, <span class="pl-s1">line2</span>]
<span class="pl-s1">lined</span> <span class="pl-c1">=</span> {}  <span class="pl-c"># Will map legend lines to original lines.</span>
<span class="pl-k">for</span> <span class="pl-s1">legline</span>, <span class="pl-s1">origline</span> <span class="pl-c1">in</span> <span class="pl-en">zip</span>(<span class="pl-s1">leg</span>.<span class="pl-en">get_lines</span>(), <span class="pl-s1">lines</span>):
    <span class="pl-s1">legline</span>.<span class="pl-en">set_picker</span>(<span class="pl-c1">True</span>)  <span class="pl-c"># Enable picking on the legend line.</span>
    <span class="pl-s1">lined</span>[<span class="pl-s1">legline</span>] <span class="pl-c1">=</span> <span class="pl-s1">origline</span>


<span class="pl-k">def</span> <span class="pl-en">on_pick</span>(<span class="pl-s1">event</span>):
    <span class="pl-c"># On the pick event, find the original line corresponding to the legend</span>
    <span class="pl-c"># proxy line, and toggle its visibility.</span>
    <span class="pl-s1">legline</span> <span class="pl-c1">=</span> <span class="pl-s1">event</span>.<span class="pl-s1">artist</span>
    <span class="pl-s1">origline</span> <span class="pl-c1">=</span> <span class="pl-s1">lined</span>[<span class="pl-s1">legline</span>]
    <span class="pl-s1">visible</span> <span class="pl-c1">=</span> <span class="pl-c1">not</span> <span class="pl-s1">origline</span>.<span class="pl-en">get_visible</span>()
    <span class="pl-s1">origline</span>.<span class="pl-en">set_visible</span>(<span class="pl-s1">visible</span>)
    <span class="pl-c"># Change the alpha on the line in the legend so we can see what lines</span>
    <span class="pl-c"># have been toggled.</span>
    <span class="pl-s1">legline</span>.<span class="pl-en">set_alpha</span>(<span class="pl-c1">1.0</span> <span class="pl-k">if</span> <span class="pl-s1">visible</span> <span class="pl-k">else</span> <span class="pl-c1">0.2</span>)
    <span class="pl-s1">fig</span>.<span class="pl-s1">canvas</span>.<span class="pl-en">draw</span>()

<span class="pl-s1">fig</span>.<span class="pl-s1">canvas</span>.<span class="pl-en">mpl_connect</span>(<span class="pl-s">'pick_event'</span>, <span class="pl-s1">on_pick</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">It graphs fine, but I can't toggle visibility by clicking the legend.<br>
I've tried executing the code from my Mac Terminal and from an IDE (Spyder) with Python 3.8.12 and matplotlib version 3.5.1.</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">I should be able to click and toggle the visibility.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">Legend picking with this script still works from my other Spyder app, which has python 3.9.2 and matplotlib 3.3.4.</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">macOS Monterey</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.1</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">MacOSX</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.8.12</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Installation</h3>
<p dir="auto">conda</p>