<h3 dir="auto">Bug report</h3>

<p dir="auto">Hi,<br>
I have a notebook that allows to draw geometrical shapes using mouse, and buttons from matplotlib.widgets.<br>
After upgrade from matplotlib 3.1.1 to 3.3.1,  my interactive plot has become excruciatingly slow.<br>
It used to work fine with "%matplotlib notebook" under matplotlib 3.3.1.</p>
<p dir="auto">Accessorily, %matplotlib notebook works for me only in chrome with 3.3.1, not firefox anymore.<br>
However, the code works with also with "%matplotlib widgets" and "%matplotlib ipympl"<br>
on both firefox and chrome, but it is slow in all cases with version matplotlib 3.3.1.</p>
<p dir="auto">I can revert to matplotlib 3.1.1 but that considerably restricts my options due to lack of compatibility with other modules I'd like to use jointly (in particular pygimli).</p>
<p dir="auto">Any help appreciated</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="# Paste your code here
####
# Here is the code example. This is what it does:
#      allows to draw polygons with mouse clicks
#      automatically labels the polygons each time &quot;next poly&quot; button is clicked
#      allows to delete any of the polygons by specifying the label in inteactive text box and clickin g butto &quot;delete poly&quot;
####

# first, import modules:
import numpy as np
%matplotlib notebook
import matplotlib.pyplot as plt
from matplotlib.widgets import Button, TextBox
from operator import itemgetter 

##################

# second, define a few functions:
def onclick2(event): 
    global pos
    if event.inaxes in [ax1] and event.button == 1: 
        ax1.text(event.xdata, event.ydata, 'o', color='r', weight='bold',\
          horizontalalignment='center',verticalalignment='center');
        pos.append([event.xdata,event.ydata])
        #ax1.set_title('%.1f' % pos[-1:][0][0] + ',' + '%.1f' % pos[-1:][0][1])

def f_next(event):
    global pos,apos,pop,axpos,aypos,axposp,ayposp
    if event.inaxes in [ax_next] and event.button == 1:
        pop = np.array(pos).T.tolist()
        pos=[]
        axpos.append(pop[0])
        aypos.append(pop[1])
        ax1.clear()
        ax1.set_xlim(left,right);ax1.set_ylim(bottom,top)
        f_replot()
        
def f_delone(event):
    global axpos,aypos
    if event.inaxes in [ax_delone] and event.button == 1:
        del axpos[ddata-1]
        del aypos[ddata-1]
        f_replot()
        pos=[]    
        
def getx(lst):
    xx=list(map(itemgetter(0), lst))
    return(xx)   

def gety(lst):
    yy=list(map(itemgetter(1), lst))
    return(yy)

def f_replot():
    ax1.clear()
    ax1.set_xlim(left,right);ax1.set_ylim(bottom,top)
    for ii in range(len(axpos)):
        ax1.plot(axpos[ii],aypos[ii],'o');
        ax1.plot(axpos[ii] + [axpos[ii][0]],aypos[ii] + [aypos[ii][0]],'-');
        ax1.text(axpos[ii][0],aypos[ii][0], str(1+ii));
    for ii in range(len(layers)):
        ax1.plot(getx(layers[ii]),gety(layers[ii]),'-')

def f_plotlayers():
    ax1.set_xlim(left,right);ax1.set_ylim(bottom,top)
    for ii in range(len(layers)):
        ax1.plot(getx(layers[ii]),gety(layers[ii]),'-')

def f_textbox(text):
    global ddata
    ddata = int(text)

def all_buttons():
    global ax_next,ax_delall,ax_texbox,ax_delone,ax_save,ax_read,ax_filename
    global b_next, b_delall, b_textbox, b_delone, b_save, b_filename, b_read 
    ax_next = fig0.add_axes([0.10, 0.07+0.2*hi+.5, 0.1, 0.075])
    ax_textbox = fig0.add_axes([0.5,0.07+0.2*hi+.5,0.08,0.075])
    ax_delone = fig0.add_axes([0.5,0.07+0.11*hi+.5,0.08,0.075])
    #
    b_next = Button(ax_next, 'Next poly',hovercolor='green')
    b_next.on_clicked(f_next)
    b_textbox = TextBox(ax_textbox, 'Del. nr:', initial=&quot; &quot;)
    b_textbox.on_text_change(f_textbox)
    b_delone = Button(ax_delone, 'Del poly', hovercolor='red')
    b_delone.on_clicked(f_delone)

###############################################

# third, construct a plot and launch the interaction, by calling &quot;all_buttons() and mpl_connect with &quot;onclick2&quot;:

top=10;bottom=-60;left=0;right=256;# model size
layers=[]
# First &quot;layer&quot; is topography [[x0,y0], [x1,y1], ... [xn,yn]] i.e., flat horizontal [[0,0],[333,0]]:
layers.append([[0,0],[50,0],[60,3],[67,4],[70,3],[73,0],[256,0]])
# add as many layers as needed, or none. Negative is down:
layers.append([[0,-20],[256,-20]])
layers.append([[0,-30],[256,-50]])
mle=max([top-bottom,left-right])
hi=(top-bottom)/mle
wi=(right-left)/mle
pos=[]; mona='m_tmp.csv'
fig0 = plt.figure(figsize=(8,4));
ax1 = fig0.add_axes([0.07, 0.07, 0.2*wi, 0.2*hi*2]) #[left bottom width height]
ax1.set_xlim(left,right);ax1.set_ylim(bottom,top)

all_buttons()
f_plotlayers()
if 'axpos' in globals(): 
    for i in range(len(axpos)): 
        f_replot()
else:
    axpos=[]; aypos=[];
#
cid=fig0.canvas.mpl_connect('button_press_event', onclick2)
#
###########################"><pre class="notranslate"><span class="pl-c"># Paste your code here</span>
<span class="pl-c">####</span>
<span class="pl-c"># Here is the code example. This is what it does:</span>
<span class="pl-c">#      allows to draw polygons with mouse clicks</span>
<span class="pl-c">#      automatically labels the polygons each time "next poly" button is clicked</span>
<span class="pl-c">#      allows to delete any of the polygons by specifying the label in inteactive text box and clickin g butto "delete poly"</span>
<span class="pl-c">####</span>

<span class="pl-c"># first, import modules:</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-c1">%</span><span class="pl-s1">matplotlib</span> <span class="pl-s1">notebook</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">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">widgets</span> <span class="pl-k">import</span> <span class="pl-v">Button</span>, <span class="pl-v">TextBox</span>
<span class="pl-k">from</span> <span class="pl-s1">operator</span> <span class="pl-k">import</span> <span class="pl-s1">itemgetter</span> 

<span class="pl-c">##################</span>

<span class="pl-c"># second, define a few functions:</span>
<span class="pl-k">def</span> <span class="pl-en">onclick2</span>(<span class="pl-s1">event</span>): 
    <span class="pl-k">global</span> <span class="pl-s1">pos</span>
    <span class="pl-k">if</span> <span class="pl-s1">event</span>.<span class="pl-s1">inaxes</span> <span class="pl-c1">in</span> [<span class="pl-s1">ax1</span>] <span class="pl-c1">and</span> <span class="pl-s1">event</span>.<span class="pl-s1">button</span> <span class="pl-c1">==</span> <span class="pl-c1">1</span>: 
        <span class="pl-s1">ax1</span>.<span class="pl-en">text</span>(<span class="pl-s1">event</span>.<span class="pl-s1">xdata</span>, <span class="pl-s1">event</span>.<span class="pl-s1">ydata</span>, <span class="pl-s">'o'</span>, <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">'r'</span>, <span class="pl-s1">weight</span><span class="pl-c1">=</span><span class="pl-s">'bold'</span>,\
          <span class="pl-s1">horizontalalignment</span><span class="pl-c1">=</span><span class="pl-s">'center'</span>,<span class="pl-s1">verticalalignment</span><span class="pl-c1">=</span><span class="pl-s">'center'</span>);
        <span class="pl-s1">pos</span>.<span class="pl-en">append</span>([<span class="pl-s1">event</span>.<span class="pl-s1">xdata</span>,<span class="pl-s1">event</span>.<span class="pl-s1">ydata</span>])
        <span class="pl-c">#ax1.set_title('%.1f' % pos[-1:][0][0] + ',' + '%.1f' % pos[-1:][0][1])</span>

<span class="pl-k">def</span> <span class="pl-en">f_next</span>(<span class="pl-s1">event</span>):
    <span class="pl-k">global</span> <span class="pl-s1">pos</span>,<span class="pl-s1">apos</span>,<span class="pl-s1">pop</span>,<span class="pl-s1">axpos</span>,<span class="pl-s1">aypos</span>,<span class="pl-s1">axposp</span>,<span class="pl-s1">ayposp</span>
    <span class="pl-k">if</span> <span class="pl-s1">event</span>.<span class="pl-s1">inaxes</span> <span class="pl-c1">in</span> [<span class="pl-s1">ax_next</span>] <span class="pl-c1">and</span> <span class="pl-s1">event</span>.<span class="pl-s1">button</span> <span class="pl-c1">==</span> <span class="pl-c1">1</span>:
        <span class="pl-s1">pop</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-s1">pos</span>).<span class="pl-v">T</span>.<span class="pl-en">tolist</span>()
        <span class="pl-s1">pos</span><span class="pl-c1">=</span>[]
        <span class="pl-s1">axpos</span>.<span class="pl-en">append</span>(<span class="pl-s1">pop</span>[<span class="pl-c1">0</span>])
        <span class="pl-s1">aypos</span>.<span class="pl-en">append</span>(<span class="pl-s1">pop</span>[<span class="pl-c1">1</span>])
        <span class="pl-s1">ax1</span>.<span class="pl-en">clear</span>()
        <span class="pl-s1">ax1</span>.<span class="pl-en">set_xlim</span>(<span class="pl-s1">left</span>,<span class="pl-s1">right</span>);<span class="pl-s1">ax1</span>.<span class="pl-en">set_ylim</span>(<span class="pl-s1">bottom</span>,<span class="pl-s1">top</span>)
        <span class="pl-en">f_replot</span>()
        
<span class="pl-k">def</span> <span class="pl-en">f_delone</span>(<span class="pl-s1">event</span>):
    <span class="pl-k">global</span> <span class="pl-s1">axpos</span>,<span class="pl-s1">aypos</span>
    <span class="pl-k">if</span> <span class="pl-s1">event</span>.<span class="pl-s1">inaxes</span> <span class="pl-c1">in</span> [<span class="pl-s1">ax_delone</span>] <span class="pl-c1">and</span> <span class="pl-s1">event</span>.<span class="pl-s1">button</span> <span class="pl-c1">==</span> <span class="pl-c1">1</span>:
        <span class="pl-k">del</span> <span class="pl-s1">axpos</span>[<span class="pl-s1">ddata</span><span class="pl-c1">-</span><span class="pl-c1">1</span>]
        <span class="pl-k">del</span> <span class="pl-s1">aypos</span>[<span class="pl-s1">ddata</span><span class="pl-c1">-</span><span class="pl-c1">1</span>]
        <span class="pl-en">f_replot</span>()
        <span class="pl-s1">pos</span><span class="pl-c1">=</span>[]    
        
<span class="pl-k">def</span> <span class="pl-en">getx</span>(<span class="pl-s1">lst</span>):
    <span class="pl-s1">xx</span><span class="pl-c1">=</span><span class="pl-en">list</span>(<span class="pl-en">map</span>(<span class="pl-en">itemgetter</span>(<span class="pl-c1">0</span>), <span class="pl-s1">lst</span>))
    <span class="pl-k">return</span>(<span class="pl-s1">xx</span>)   

<span class="pl-k">def</span> <span class="pl-en">gety</span>(<span class="pl-s1">lst</span>):
    <span class="pl-s1">yy</span><span class="pl-c1">=</span><span class="pl-en">list</span>(<span class="pl-en">map</span>(<span class="pl-en">itemgetter</span>(<span class="pl-c1">1</span>), <span class="pl-s1">lst</span>))
    <span class="pl-k">return</span>(<span class="pl-s1">yy</span>)

<span class="pl-k">def</span> <span class="pl-en">f_replot</span>():
    <span class="pl-s1">ax1</span>.<span class="pl-en">clear</span>()
    <span class="pl-s1">ax1</span>.<span class="pl-en">set_xlim</span>(<span class="pl-s1">left</span>,<span class="pl-s1">right</span>);<span class="pl-s1">ax1</span>.<span class="pl-en">set_ylim</span>(<span class="pl-s1">bottom</span>,<span class="pl-s1">top</span>)
    <span class="pl-k">for</span> <span class="pl-s1">ii</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">axpos</span>)):
        <span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>(<span class="pl-s1">axpos</span>[<span class="pl-s1">ii</span>],<span class="pl-s1">aypos</span>[<span class="pl-s1">ii</span>],<span class="pl-s">'o'</span>);
        <span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>(<span class="pl-s1">axpos</span>[<span class="pl-s1">ii</span>] <span class="pl-c1">+</span> [<span class="pl-s1">axpos</span>[<span class="pl-s1">ii</span>][<span class="pl-c1">0</span>]],<span class="pl-s1">aypos</span>[<span class="pl-s1">ii</span>] <span class="pl-c1">+</span> [<span class="pl-s1">aypos</span>[<span class="pl-s1">ii</span>][<span class="pl-c1">0</span>]],<span class="pl-s">'-'</span>);
        <span class="pl-s1">ax1</span>.<span class="pl-en">text</span>(<span class="pl-s1">axpos</span>[<span class="pl-s1">ii</span>][<span class="pl-c1">0</span>],<span class="pl-s1">aypos</span>[<span class="pl-s1">ii</span>][<span class="pl-c1">0</span>], <span class="pl-en">str</span>(<span class="pl-c1">1</span><span class="pl-c1">+</span><span class="pl-s1">ii</span>));
    <span class="pl-k">for</span> <span class="pl-s1">ii</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">layers</span>)):
        <span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>(<span class="pl-en">getx</span>(<span class="pl-s1">layers</span>[<span class="pl-s1">ii</span>]),<span class="pl-en">gety</span>(<span class="pl-s1">layers</span>[<span class="pl-s1">ii</span>]),<span class="pl-s">'-'</span>)

<span class="pl-k">def</span> <span class="pl-en">f_plotlayers</span>():
    <span class="pl-s1">ax1</span>.<span class="pl-en">set_xlim</span>(<span class="pl-s1">left</span>,<span class="pl-s1">right</span>);<span class="pl-s1">ax1</span>.<span class="pl-en">set_ylim</span>(<span class="pl-s1">bottom</span>,<span class="pl-s1">top</span>)
    <span class="pl-k">for</span> <span class="pl-s1">ii</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">layers</span>)):
        <span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>(<span class="pl-en">getx</span>(<span class="pl-s1">layers</span>[<span class="pl-s1">ii</span>]),<span class="pl-en">gety</span>(<span class="pl-s1">layers</span>[<span class="pl-s1">ii</span>]),<span class="pl-s">'-'</span>)

<span class="pl-k">def</span> <span class="pl-en">f_textbox</span>(<span class="pl-s1">text</span>):
    <span class="pl-k">global</span> <span class="pl-s1">ddata</span>
    <span class="pl-s1">ddata</span> <span class="pl-c1">=</span> <span class="pl-en">int</span>(<span class="pl-s1">text</span>)

<span class="pl-k">def</span> <span class="pl-en">all_buttons</span>():
    <span class="pl-k">global</span> <span class="pl-s1">ax_next</span>,<span class="pl-s1">ax_delall</span>,<span class="pl-s1">ax_texbox</span>,<span class="pl-s1">ax_delone</span>,<span class="pl-s1">ax_save</span>,<span class="pl-s1">ax_read</span>,<span class="pl-s1">ax_filename</span>
    <span class="pl-k">global</span> <span class="pl-s1">b_next</span>, <span class="pl-s1">b_delall</span>, <span class="pl-s1">b_textbox</span>, <span class="pl-s1">b_delone</span>, <span class="pl-s1">b_save</span>, <span class="pl-s1">b_filename</span>, <span class="pl-s1">b_read</span> 
    <span class="pl-s1">ax_next</span> <span class="pl-c1">=</span> <span class="pl-s1">fig0</span>.<span class="pl-en">add_axes</span>([<span class="pl-c1">0.10</span>, <span class="pl-c1">0.07</span><span class="pl-c1">+</span><span class="pl-c1">0.2</span><span class="pl-c1">*</span><span class="pl-s1">hi</span><span class="pl-c1">+</span><span class="pl-c1">.5</span>, <span class="pl-c1">0.1</span>, <span class="pl-c1">0.075</span>])
    <span class="pl-s1">ax_textbox</span> <span class="pl-c1">=</span> <span class="pl-s1">fig0</span>.<span class="pl-en">add_axes</span>([<span class="pl-c1">0.5</span>,<span class="pl-c1">0.07</span><span class="pl-c1">+</span><span class="pl-c1">0.2</span><span class="pl-c1">*</span><span class="pl-s1">hi</span><span class="pl-c1">+</span><span class="pl-c1">.5</span>,<span class="pl-c1">0.08</span>,<span class="pl-c1">0.075</span>])
    <span class="pl-s1">ax_delone</span> <span class="pl-c1">=</span> <span class="pl-s1">fig0</span>.<span class="pl-en">add_axes</span>([<span class="pl-c1">0.5</span>,<span class="pl-c1">0.07</span><span class="pl-c1">+</span><span class="pl-c1">0.11</span><span class="pl-c1">*</span><span class="pl-s1">hi</span><span class="pl-c1">+</span><span class="pl-c1">.5</span>,<span class="pl-c1">0.08</span>,<span class="pl-c1">0.075</span>])
    <span class="pl-c">#</span>
    <span class="pl-s1">b_next</span> <span class="pl-c1">=</span> <span class="pl-v">Button</span>(<span class="pl-s1">ax_next</span>, <span class="pl-s">'Next poly'</span>,<span class="pl-s1">hovercolor</span><span class="pl-c1">=</span><span class="pl-s">'green'</span>)
    <span class="pl-s1">b_next</span>.<span class="pl-en">on_clicked</span>(<span class="pl-s1">f_next</span>)
    <span class="pl-s1">b_textbox</span> <span class="pl-c1">=</span> <span class="pl-v">TextBox</span>(<span class="pl-s1">ax_textbox</span>, <span class="pl-s">'Del. nr:'</span>, <span class="pl-s1">initial</span><span class="pl-c1">=</span><span class="pl-s">" "</span>)
    <span class="pl-s1">b_textbox</span>.<span class="pl-en">on_text_change</span>(<span class="pl-s1">f_textbox</span>)
    <span class="pl-s1">b_delone</span> <span class="pl-c1">=</span> <span class="pl-v">Button</span>(<span class="pl-s1">ax_delone</span>, <span class="pl-s">'Del poly'</span>, <span class="pl-s1">hovercolor</span><span class="pl-c1">=</span><span class="pl-s">'red'</span>)
    <span class="pl-s1">b_delone</span>.<span class="pl-en">on_clicked</span>(<span class="pl-s1">f_delone</span>)

<span class="pl-c">###############################################</span>

<span class="pl-c"># third, construct a plot and launch the interaction, by calling "all_buttons() and mpl_connect with "onclick2":</span>

<span class="pl-s1">top</span><span class="pl-c1">=</span><span class="pl-c1">10</span>;<span class="pl-s1">bottom</span><span class="pl-c1">=</span><span class="pl-c1">-</span><span class="pl-c1">60</span>;<span class="pl-s1">left</span><span class="pl-c1">=</span><span class="pl-c1">0</span>;<span class="pl-s1">right</span><span class="pl-c1">=</span><span class="pl-c1">256</span>;<span class="pl-c"># model size</span>
<span class="pl-s1">layers</span><span class="pl-c1">=</span>[]
<span class="pl-c"># First "layer" is topography [[x0,y0], [x1,y1], ... [xn,yn]] i.e., flat horizontal [[0,0],[333,0]]:</span>
<span class="pl-s1">layers</span>.<span class="pl-en">append</span>([[<span class="pl-c1">0</span>,<span class="pl-c1">0</span>],[<span class="pl-c1">50</span>,<span class="pl-c1">0</span>],[<span class="pl-c1">60</span>,<span class="pl-c1">3</span>],[<span class="pl-c1">67</span>,<span class="pl-c1">4</span>],[<span class="pl-c1">70</span>,<span class="pl-c1">3</span>],[<span class="pl-c1">73</span>,<span class="pl-c1">0</span>],[<span class="pl-c1">256</span>,<span class="pl-c1">0</span>]])
<span class="pl-c"># add as many layers as needed, or none. Negative is down:</span>
<span class="pl-s1">layers</span>.<span class="pl-en">append</span>([[<span class="pl-c1">0</span>,<span class="pl-c1">-</span><span class="pl-c1">20</span>],[<span class="pl-c1">256</span>,<span class="pl-c1">-</span><span class="pl-c1">20</span>]])
<span class="pl-s1">layers</span>.<span class="pl-en">append</span>([[<span class="pl-c1">0</span>,<span class="pl-c1">-</span><span class="pl-c1">30</span>],[<span class="pl-c1">256</span>,<span class="pl-c1">-</span><span class="pl-c1">50</span>]])
<span class="pl-s1">mle</span><span class="pl-c1">=</span><span class="pl-en">max</span>([<span class="pl-s1">top</span><span class="pl-c1">-</span><span class="pl-s1">bottom</span>,<span class="pl-s1">left</span><span class="pl-c1">-</span><span class="pl-s1">right</span>])
<span class="pl-s1">hi</span><span class="pl-c1">=</span>(<span class="pl-s1">top</span><span class="pl-c1">-</span><span class="pl-s1">bottom</span>)<span class="pl-c1">/</span><span class="pl-s1">mle</span>
<span class="pl-s1">wi</span><span class="pl-c1">=</span>(<span class="pl-s1">right</span><span class="pl-c1">-</span><span class="pl-s1">left</span>)<span class="pl-c1">/</span><span class="pl-s1">mle</span>
<span class="pl-s1">pos</span><span class="pl-c1">=</span>[]; <span class="pl-s1">mona</span><span class="pl-c1">=</span><span class="pl-s">'m_tmp.csv'</span>
<span class="pl-s1">fig0</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-c1">8</span>,<span class="pl-c1">4</span>));
<span class="pl-s1">ax1</span> <span class="pl-c1">=</span> <span class="pl-s1">fig0</span>.<span class="pl-en">add_axes</span>([<span class="pl-c1">0.07</span>, <span class="pl-c1">0.07</span>, <span class="pl-c1">0.2</span><span class="pl-c1">*</span><span class="pl-s1">wi</span>, <span class="pl-c1">0.2</span><span class="pl-c1">*</span><span class="pl-s1">hi</span><span class="pl-c1">*</span><span class="pl-c1">2</span>]) <span class="pl-c">#[left bottom width height]</span>
<span class="pl-s1">ax1</span>.<span class="pl-en">set_xlim</span>(<span class="pl-s1">left</span>,<span class="pl-s1">right</span>);<span class="pl-s1">ax1</span>.<span class="pl-en">set_ylim</span>(<span class="pl-s1">bottom</span>,<span class="pl-s1">top</span>)

<span class="pl-en">all_buttons</span>()
<span class="pl-en">f_plotlayers</span>()
<span class="pl-k">if</span> <span class="pl-s">'axpos'</span> <span class="pl-c1">in</span> <span class="pl-en">globals</span>(): 
    <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-en">len</span>(<span class="pl-s1">axpos</span>)): 
        <span class="pl-en">f_replot</span>()
<span class="pl-k">else</span>:
    <span class="pl-s1">axpos</span><span class="pl-c1">=</span>[]; <span class="pl-s1">aypos</span><span class="pl-c1">=</span>[];
<span class="pl-c">#</span>
<span class="pl-s1">cid</span><span class="pl-c1">=</span><span class="pl-s1">fig0</span>.<span class="pl-s1">canvas</span>.<span class="pl-en">mpl_connect</span>(<span class="pl-s">'button_press_event'</span>, <span class="pl-s1">onclick2</span>)
<span class="pl-c">#</span>
<span class="pl-c">###########################</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/45072850/93027361-20464680-f604-11ea-8695-d387f8e7ea4a.png"><img src="https://user-images.githubusercontent.com/45072850/93027361-20464680-f604-11ea-8695-d387f8e7ea4a.png" alt="image" style="max-width: 100%;"></a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# If applicable, paste the console output here
#
#"><pre class="notranslate"><code class="notranslate"># If applicable, paste the console output here
#
#
</code></pre></div>
<p dir="auto"><strong>Expected outcome</strong></p>


<p dir="auto"><strong>Matplotlib version</strong><br>
matplotlib 3.1.1</p>

<ul dir="auto">
<li>Operating system: linux mint</li>
<li>Matplotlib version: 3.3.1</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): nbAgg</li>
<li>Python version: 3.7.8</li>
<li>Jupyter version (if applicable):<br>
jupyter core     : 4.6.3<br>
jupyter-notebook : 6.1.4<br>
qtconsole        : 4.7.5<br>
ipython          : 7.17.0<br>
ipykernel        : 5.3.4<br>
jupyter client   : 6.1.6<br>
jupyter lab      : not installed<br>
nbconvert        : 5.6.1<br>
ipywidgets       : 7.5.1<br>
nbformat         : 5.0.7<br>
traitlets        : 4.3.3</li>
<li>Other libraries:</li>
</ul>

<p dir="auto">installed with conda</p>

<p dir="auto">the working environment was installed from conda. Channels are:</p>
<ul dir="auto">
<li>gimli</li>
<li>anaconda</li>
<li>conda-forge</li>
<li>defaults<br>
######################################################</li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">I encountered a performance regression starting in Matplotlib v3.3.0 when using a figure with a button widget. Any mouse motion appears to trigger canvas draw events. The issue bisected to commit <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/matplotlib/matplotlib/commit/f6b88917ac2a1c2fdfe25c144d1b81bd7003b3d1/hovercard" href="https://github.com/matplotlib/matplotlib/commit/f6b88917ac2a1c2fdfe25c144d1b81bd7003b3d1"><tt>f6b8891</tt></a> and is not present in v3.2.2.</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="from matplotlib import pyplot as plt
from matplotlib.widgets import Button

if __name__ == &quot;__main__&quot;:
    def on_draw(evt):
        global redraw_count
        redraw_count += 1
        btn.label.set_text(btn_txt.format(redraw_count))
    
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    redraw_count = 0
    btn_txt = &quot;Redraws: {}&quot;
    btn = Button(ax, btn_txt.format(redraw_count))
    fig.canvas.mpl_connect(&quot;draw_event&quot;, on_draw)
    plt.show()
"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">import</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">widgets</span> <span class="pl-k">import</span> <span class="pl-v">Button</span>

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">"__main__"</span>:
    <span class="pl-k">def</span> <span class="pl-en">on_draw</span>(<span class="pl-s1">evt</span>):
        <span class="pl-k">global</span> <span class="pl-s1">redraw_count</span>
        <span class="pl-s1">redraw_count</span> <span class="pl-c1">+=</span> <span class="pl-c1">1</span>
        <span class="pl-s1">btn</span>.<span class="pl-s1">label</span>.<span class="pl-en">set_text</span>(<span class="pl-s1">btn_txt</span>.<span class="pl-en">format</span>(<span class="pl-s1">redraw_count</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">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>)
    <span class="pl-s1">redraw_count</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
    <span class="pl-s1">btn_txt</span> <span class="pl-c1">=</span> <span class="pl-s">"Redraws: {}"</span>
    <span class="pl-s1">btn</span> <span class="pl-c1">=</span> <span class="pl-v">Button</span>(<span class="pl-s1">ax</span>, <span class="pl-s1">btn_txt</span>.<span class="pl-en">format</span>(<span class="pl-s1">redraw_count</span>))
    <span class="pl-s1">fig</span>.<span class="pl-s1">canvas</span>.<span class="pl-en">mpl_connect</span>(<span class="pl-s">"draw_event"</span>, <span class="pl-s1">on_draw</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">Motion anywhere in the figure increments the number of redraw events. The issue appears to result from the comparison between the Button's stored color value and the Axes's returned facecolor (see <a href="https://github.com/matplotlib/matplotlib/blob/v3.3.1/lib/matplotlib/widgets.py#L214">here</a>). The default Button color is given and stored as a string of a float, while the Axes <code class="notranslate">get_facecolor</code> returns a tuple in RGBA format.</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">Redraws are only triggered when moving into or out of the button to show the hover color change. A workaround is to give the <code class="notranslate">color</code> and <code class="notranslate">hovercolor</code> parameters to <code class="notranslate">Button</code> as RGBA values, such as:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="btn = Button(ax, &quot;Label&quot;, color=(0.2, 0.3, 0.4, 1.0), hovercolor=(0.3, 0.4, 0.5, 1.0))"><pre class="notranslate"><code class="notranslate">btn = Button(ax, "Label", color=(0.2, 0.3, 0.4, 1.0), hovercolor=(0.3, 0.4, 0.5, 1.0))
</code></pre></div>
<p dir="auto">A fix would be to convert the found color value in the <code class="notranslate">Button._motion</code> function to RGBA when comparing with the current facecolor, such as this change in the <code class="notranslate">Button</code> class (after adding an import to <code class="notranslate">colors</code>):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    def _motion(self, event):
        if self.ignore(event):
            return
        c = self.hovercolor if event.inaxes == self.ax else self.color
        # changed c to colors.to_rgba(c)
        if colors.to_rgba(c) != self.ax.get_facecolor():
            self.ax.set_facecolor(c)
            if self.drawon:
                self.ax.figure.canvas.draw()"><pre class="notranslate"><code class="notranslate">    def _motion(self, event):
        if self.ignore(event):
            return
        c = self.hovercolor if event.inaxes == self.ax else self.color
        # changed c to colors.to_rgba(c)
        if colors.to_rgba(c) != self.ax.get_facecolor():
            self.ax.set_facecolor(c)
            if self.drawon:
                self.ax.figure.canvas.draw()
</code></pre></div>
<p dir="auto">If this seems reasonable, I can submit a PR.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>

<ul dir="auto">
<li>Operating system: macOS 10.15.5</li>
<li>Matplotlib version: 3.3.1 (tested on latest commit, <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/matplotlib/matplotlib/commit/ce6ac2d174e396abab9e17577f3721f33bd7d41f/hovercard" href="https://github.com/matplotlib/matplotlib/commit/ce6ac2d174e396abab9e17577f3721f33bd7d41f"><tt>ce6ac2d</tt></a>)</li>
<li>Matplotlib backend (<code class="notranslate">print(matplotlib.get_backend())</code>): MacOSX</li>
<li>Python version: 3.7.6</li>
<li>Jupyter version (if applicable): n/a</li>
<li>Other libraries: n/a</li>
</ul>