@@ -970,6 +970,7 @@ def __init__(self, canvas):
970
970
971
971
# a dict from axes index to a list of view limits
972
972
self ._views = Stack ()
973
+ self ._positions = Stack () # stack of subplot positions
973
974
self ._xypress = None # the location and axis info at the time of the press
974
975
self ._idPress = None
975
976
self ._idRelease = None
@@ -989,6 +990,7 @@ def set_message(self, s):
989
990
def back (self , * args ):
990
991
'move back up the view lim stack'
991
992
self ._views .back ()
993
+ self ._positions .back ()
992
994
self .set_history_buttons ()
993
995
self ._update_view ()
994
996
@@ -1002,12 +1004,14 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
1002
1004
def forward (self , * args ):
1003
1005
'move forward in the view lim stack'
1004
1006
self ._views .forward ()
1007
+ self ._positions .forward ()
1005
1008
self .set_history_buttons ()
1006
1009
self ._update_view ()
1007
1010
1008
1011
def home (self , * args ):
1009
1012
'restore the original view'
1010
1013
self ._views .home ()
1014
+ self ._positions .home ()
1011
1015
self .set_history_buttons ()
1012
1016
self ._update_view ()
1013
1017
@@ -1150,13 +1154,15 @@ def press_zoom(self, event):
1150
1154
self .press (event )
1151
1155
1152
1156
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 = []
1155
1159
for a in self .canvas .figure .get_axes ():
1156
1160
xmin , xmax = a .get_xlim ()
1157
1161
ymin , ymax = a .get_ylim ()
1158
1162
lims .append ( (xmin , xmax , ymin , ymax ) )
1163
+ pos .append ( tuple ( a .get_position () ) )
1159
1164
self ._views .push (lims )
1165
+ self ._positions .push (pos )
1160
1166
self .set_history_buttons ()
1161
1167
1162
1168
@@ -1353,14 +1359,17 @@ def draw(self):
1353
1359
1354
1360
1355
1361
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'
1357
1363
1358
1364
lims = self ._views ()
1359
1365
if lims is None : return
1366
+ pos = self ._positions ()
1367
+ if pos is None : return
1360
1368
for i , a in enumerate (self .canvas .figure .get_axes ()):
1361
1369
xmin , xmax , ymin , ymax = lims [i ]
1362
1370
a .set_xlim ((xmin , xmax ))
1363
1371
a .set_ylim ((ymin , ymax ))
1372
+ a .set_position ( pos [i ] )
1364
1373
1365
1374
self .draw ()
1366
1375
@@ -1379,6 +1388,7 @@ def set_cursor(self, cursor):
1379
1388
def update (self ):
1380
1389
'reset the axes stack'
1381
1390
self ._views .clear ()
1391
+ self ._positions .clear ()
1382
1392
self .set_history_buttons ()
1383
1393
1384
1394
def zoom (self , * args ):
0 commit comments