@@ -152,7 +152,7 @@ class Button(AxesWidget):
152
152
"""
153
153
154
154
def __init__ (self , ax , label , image = None ,
155
- color = '0.85' , hovercolor = '0.95' ):
155
+ color = '0.85' , hovercolor = '0.95' , * , useblit = True ):
156
156
"""
157
157
Parameters
158
158
----------
@@ -167,6 +167,9 @@ def __init__(self, ax, label, image=None,
167
167
The color of the button when not activated.
168
168
hovercolor : color
169
169
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.
170
173
"""
171
174
super ().__init__ (ax )
172
175
@@ -177,6 +180,8 @@ def __init__(self, ax, label, image=None,
177
180
horizontalalignment = 'center' ,
178
181
transform = ax .transAxes )
179
182
183
+ self ._useblit = useblit and self .canvas .supports_blit
184
+
180
185
self ._observers = cbook .CallbackRegistry (signals = ["clicked" ])
181
186
182
187
self .connect_event ('button_press_event' , self ._click )
@@ -209,7 +214,11 @@ def _motion(self, event):
209
214
if not colors .same_color (c , self .ax .get_facecolor ()):
210
215
self .ax .set_facecolor (c )
211
216
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 ()
213
222
214
223
def on_clicked (self , func ):
215
224
"""
0 commit comments