@@ -90,22 +90,6 @@ 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
-
109
93
110
94
class AxesWidget (Widget ):
111
95
"""
@@ -131,9 +115,10 @@ class AxesWidget(Widget):
131
115
132
116
def __init__ (self , ax ):
133
117
self .ax = ax
134
- self .canvas = ax .figure .canvas
135
118
self ._cids = []
136
119
120
+ canvas = property (lambda self : self .ax .figure .canvas )
121
+
137
122
def connect_event (self , event , callback ):
138
123
"""
139
124
Connect a callback function with an event.
@@ -1100,7 +1085,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
1100
1085
1101
1086
def _clear (self , event ):
1102
1087
"""Internal event handler to clear the buttons."""
1103
- if self .ignore (event ) or self ._changed_canvas ():
1088
+ if self .ignore (event ) or self .canvas . is_saving ():
1104
1089
return
1105
1090
self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
1106
1091
self .ax .draw_artist (self ._checks )
@@ -1677,7 +1662,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
1677
1662
1678
1663
def _clear (self , event ):
1679
1664
"""Internal event handler to clear the buttons."""
1680
- if self .ignore (event ) or self ._changed_canvas ():
1665
+ if self .ignore (event ) or self .canvas . is_saving ():
1681
1666
return
1682
1667
self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
1683
1668
self .ax .draw_artist (self ._buttons )
@@ -1933,7 +1918,7 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
1933
1918
1934
1919
def clear (self , event ):
1935
1920
"""Internal event handler to clear the cursor."""
1936
- if self .ignore (event ) or self ._changed_canvas ():
1921
+ if self .ignore (event ) or self .canvas . is_saving ():
1937
1922
return
1938
1923
if self .useblit :
1939
1924
self .background = self .canvas .copy_from_bbox (self .ax .bbox )
@@ -2573,9 +2558,7 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
2573
2558
self .drag_from_anywhere = drag_from_anywhere
2574
2559
self .ignore_event_outside = ignore_event_outside
2575
2560
2576
- # Reset canvas so that `new_axes` connects events.
2577
- self .canvas = None
2578
- self .new_axes (ax , _props = props )
2561
+ self .new_axes (ax , _props = props , _init = True )
2579
2562
2580
2563
# Setup handles
2581
2564
self ._handle_props = {
@@ -2588,14 +2571,12 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
2588
2571
2589
2572
self ._active_handle = None
2590
2573
2591
- def new_axes (self , ax , * , _props = None ):
2574
+ def new_axes (self , ax , * , _props = None , _init = False ):
2592
2575
"""Set SpanSelector to operate on a new Axes."""
2593
2576
self .ax = ax
2594
- if self .canvas is not ax .figure .canvas :
2577
+ if _init or self .canvas is not ax .figure .canvas :
2595
2578
if self .canvas is not None :
2596
2579
self .disconnect_events ()
2597
-
2598
- self .canvas = ax .figure .canvas
2599
2580
self .connect_default_events ()
2600
2581
2601
2582
# Reset
0 commit comments