@@ -152,7 +152,7 @@ class Button(AxesWidget):
152152 """
153153
154154 def __init__ (self , ax , label , image = None ,
155- color = '0.85' , hovercolor = '0.95' ):
155+ color = '0.85' , hovercolor = '0.95' , * , useblit = True ):
156156 """
157157 Parameters
158158 ----------
@@ -167,6 +167,9 @@ def __init__(self, ax, label, image=None,
167167 The color of the button when not activated.
168168 hovercolor : color
169169 The color of the button when the mouse is over it.
170+ useblit : bool, default: True
171+ Use blitting for faster drawing if supported by the backend.
172+ See the tutorial :doc:`/tutorials/advanced/blitting` for details.
170173 """
171174 super ().__init__ (ax )
172175
@@ -177,6 +180,8 @@ def __init__(self, ax, label, image=None,
177180 horizontalalignment = 'center' ,
178181 transform = ax .transAxes )
179182
183+ self ._useblit = useblit and self .canvas .supports_blit
184+
180185 self ._observers = cbook .CallbackRegistry (signals = ["clicked" ])
181186
182187 self .connect_event ('button_press_event' , self ._click )
@@ -209,7 +214,11 @@ def _motion(self, event):
209214 if not colors .same_color (c , self .ax .get_facecolor ()):
210215 self .ax .set_facecolor (c )
211216 if self .drawon :
212- self .ax .figure .canvas .draw ()
217+ if self ._useblit :
218+ self .ax .draw_artist (self .ax )
219+ self .canvas .blit (self .ax .bbox )
220+ else :
221+ self .canvas .draw ()
213222
214223 def on_clicked (self , func ):
215224 """
0 commit comments