@@ -90,22 +90,6 @@ 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-
10993
11094class AxesWidget (Widget ):
11195 """
@@ -131,9 +115,10 @@ class AxesWidget(Widget):
131115
132116 def __init__ (self , ax ):
133117 self .ax = ax
134- self .canvas = ax .figure .canvas
135118 self ._cids = []
136119
120+ canvas = property (lambda self : self .ax .figure .canvas )
121+
137122 def connect_event (self , event , callback ):
138123 """
139124 Connect a callback function with an event.
@@ -1100,7 +1085,7 @@ def __init__(self, ax, labels, actives=None, *, useblit=True,
11001085
11011086 def _clear (self , event ):
11021087 """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 ():
11041089 return
11051090 self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
11061091 self .ax .draw_artist (self ._checks )
@@ -1677,7 +1662,7 @@ def __init__(self, ax, labels, active=0, activecolor=None, *,
16771662
16781663 def _clear (self , event ):
16791664 """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 ():
16811666 return
16821667 self ._background = self .canvas .copy_from_bbox (self .ax .bbox )
16831668 self .ax .draw_artist (self ._buttons )
@@ -1933,7 +1918,7 @@ def __init__(self, ax, *, horizOn=True, vertOn=True, useblit=False,
19331918
19341919 def clear (self , event ):
19351920 """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 ():
19371922 return
19381923 if self .useblit :
19391924 self .background = self .canvas .copy_from_bbox (self .ax .bbox )
@@ -2573,9 +2558,7 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25732558 self .drag_from_anywhere = drag_from_anywhere
25742559 self .ignore_event_outside = ignore_event_outside
25752560
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 )
25792562
25802563 # Setup handles
25812564 self ._handle_props = {
@@ -2588,14 +2571,12 @@ def __init__(self, ax, onselect, direction, *, minspan=0, useblit=False,
25882571
25892572 self ._active_handle = None
25902573
2591- def new_axes (self , ax , * , _props = None ):
2574+ def new_axes (self , ax , * , _props = None , _init = False ):
25922575 """Set SpanSelector to operate on a new Axes."""
25932576 self .ax = ax
2594- if self .canvas is not ax .figure .canvas :
2577+ if _init or self .canvas is not ax .figure .canvas :
25952578 if self .canvas is not None :
25962579 self .disconnect_events ()
2597-
2598- self .canvas = ax .figure .canvas
25992580 self .connect_default_events ()
26002581
26012582 # Reset
0 commit comments