Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33669e9

Browse files
committed
Add blitting support on Button widgets
1 parent 3393a4f commit 33669e9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/matplotlib/widgets.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)