@@ -970,6 +970,7 @@ def __init__(self, canvas):
970970
971971 # a dict from axes index to a list of view limits
972972 self ._views = Stack ()
973+ self ._positions = Stack () # stack of subplot positions
973974 self ._xypress = None # the location and axis info at the time of the press
974975 self ._idPress = None
975976 self ._idRelease = None
@@ -989,6 +990,7 @@ def set_message(self, s):
989990 def back (self , * args ):
990991 'move back up the view lim stack'
991992 self ._views .back ()
993+ self ._positions .back ()
992994 self .set_history_buttons ()
993995 self ._update_view ()
994996
@@ -1002,12 +1004,14 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
10021004 def forward (self , * args ):
10031005 'move forward in the view lim stack'
10041006 self ._views .forward ()
1007+ self ._positions .forward ()
10051008 self .set_history_buttons ()
10061009 self ._update_view ()
10071010
10081011 def home (self , * args ):
10091012 'restore the original view'
10101013 self ._views .home ()
1014+ self ._positions .home ()
10111015 self .set_history_buttons ()
10121016 self ._update_view ()
10131017
@@ -1150,13 +1154,15 @@ def press_zoom(self, event):
11501154 self .press (event )
11511155
11521156 def push_current (self ):
1153- 'push the current view limits onto the stack'
1154- lims = []
1157+ 'push the current view limits and position onto the stack'
1158+ lims = []; pos = []
11551159 for a in self .canvas .figure .get_axes ():
11561160 xmin , xmax = a .get_xlim ()
11571161 ymin , ymax = a .get_ylim ()
11581162 lims .append ( (xmin , xmax , ymin , ymax ) )
1163+ pos .append ( tuple ( a .get_position () ) )
11591164 self ._views .push (lims )
1165+ self ._positions .push (pos )
11601166 self .set_history_buttons ()
11611167
11621168
@@ -1353,14 +1359,17 @@ def draw(self):
13531359
13541360
13551361 def _update_view (self ):
1356- 'update the viewlim from the view stack for each axes'
1362+ 'update the viewlim and position from the view and position stack for each axes'
13571363
13581364 lims = self ._views ()
13591365 if lims is None : return
1366+ pos = self ._positions ()
1367+ if pos is None : return
13601368 for i , a in enumerate (self .canvas .figure .get_axes ()):
13611369 xmin , xmax , ymin , ymax = lims [i ]
13621370 a .set_xlim ((xmin , xmax ))
13631371 a .set_ylim ((ymin , ymax ))
1372+ a .set_position ( pos [i ] )
13641373
13651374 self .draw ()
13661375
@@ -1379,6 +1388,7 @@ def set_cursor(self, cursor):
13791388 def update (self ):
13801389 'reset the axes stack'
13811390 self ._views .clear ()
1391+ self ._positions .clear ()
13821392 self .set_history_buttons ()
13831393
13841394 def zoom (self , * args ):
0 commit comments