@@ -90,6 +90,22 @@ def ignore(self, event):
90
90
"""
91
91
return not self .active
92
92
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
+
93
109
94
110
class AxesWidget (Widget ):
95
111
"""
@@ -1088,7 +1104,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
1088
1104
1089
1105
def _clear (self , event ):
1090
1106
"""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 () :
1092
1108
return
1093
1109
self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
1094
1110
self .ax .draw_artist (self ._checks )
@@ -1700,7 +1716,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
1700
1716
1701
1717
def _clear (self , event ):
1702
1718
"""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 () :
1704
1720
return
1705
1721
self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
1706
1722
self .ax .draw_artist (self ._buttons )
@@ -1971,7 +1987,7 @@ def __init__(self, ax, horizOn=True, vertOn=True, useblit=False,
1971
1987
1972
1988
def clear (self , event ):
1973
1989
"""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 () :
1975
1991
return
1976
1992
if self .useblit :
1977
1993
self .background = self .canvas .copy_from_bbox (self .ax .bbox )
0 commit comments