Skip to content

Commit 6bb208d

Browse files
committed
MNT: put changed canvas logic in private method with docstring
1 parent faa4816 commit 6bb208d

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

lib/matplotlib/widgets.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,22 @@ def ignore(self, event):
9090
"""
9191
return not self.active
9292

93+
def _changed_canvas(self):
94+
"""
95+
Someone has switched the canvas on us!
96+
97+
This happens if `savefig` needs to save to a format the previous
98+
backend did not support (e.g. saving a figure using an Agg based
99+
backend saved to a vector format).
100+
101+
Returns
102+
-------
103+
bool
104+
True if the canvas has been changed.
105+
106+
"""
107+
return self.canvas is not self.ax.figure.canvas
108+
93109

94110
class AxesWidget(Widget):
95111
"""
@@ -1088,7 +1104,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
10881104

10891105
def _clear(self, event):
10901106
"""Internal event handler to clear the buttons."""
1091-
if self.ignore(event) or self.canvas is not self.ax.figure.canvas:
1107+
if self.ignore(event) or self._changed_canvas():
10921108
return
10931109
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
10941110
self.ax.draw_artist(self._checks)
@@ -1700,7 +1716,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
17001716

17011717
def _clear(self, event):
17021718
"""Internal event handler to clear the buttons."""
1703-
if self.ignore(event) or self.canvas is not self.ax.figure.canvas:
1719+
if self.ignore(event) or self._changed_canvas():
17041720
return
17051721
self._background = self.canvas.copy_from_bbox(self.ax.bbox)
17061722
self.ax.draw_artist(self._buttons)
@@ -1971,7 +1987,7 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
19711987

19721988
def clear(self, event):
19731989
"""Internal event handler to clear the cursor."""
1974-
if self.ignore(event) or self.canvas is not self.ax.figure.canvas:
1990+
if self.ignore(event) or self._changed_canvas():
19751991
return
19761992
if self.useblit:
19771993
self.background = self.canvas.copy_from_bbox(self.ax.bbox)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy