@@ -341,6 +341,7 @@ def __init__(self, fig, rect,
341
341
):
342
342
Artist .__init__ (self )
343
343
self ._position = map (makeValue , rect )
344
+ self ._originalPosition = rect
344
345
# must be set before set_figure
345
346
self ._sharex = sharex
346
347
self ._sharey = sharey
@@ -372,7 +373,6 @@ def __init__(self, fig, rect,
372
373
# aspect ratio atribute, and original position
373
374
self .set_aspect ('auto' )
374
375
self .set_aspect_adjusts ('position' )
375
- self ._originalPosition = self .get_position ()
376
376
377
377
if len (kwargs ): setp (self , ** kwargs )
378
378
@@ -1403,8 +1403,8 @@ def draw(self, renderer=None, inframe=False):
1403
1403
raise RuntimeError ('No renderer defined' )
1404
1404
if not self .get_visible (): return
1405
1405
renderer .open_group ('axes' )
1406
-
1407
1406
self .apply_aspect ()
1407
+
1408
1408
try : self .transData .freeze () # eval the lazy objects
1409
1409
except ValueError :
1410
1410
print >> sys .stderr , 'data freeze value error' , self .get_position (), self .dataLim .get_bounds (), self .viewLim .get_bounds ()
@@ -1477,7 +1477,6 @@ def draw(self, renderer=None, inframe=False):
1477
1477
1478
1478
self ._cachedRenderer = renderer
1479
1479
1480
-
1481
1480
def __draw_animate (self ):
1482
1481
# ignore for now; broken
1483
1482
if self ._lastRenderer is None :
@@ -2438,7 +2437,7 @@ def pcolormesh(self, *args, **kwargs):
2438
2437
coords [:, 1 ] = Y .astype (Float32 )
2439
2438
#print coords
2440
2439
2441
- if shading == 'faceted' :
2440
+ if shading == 'faceted' :
2442
2441
showedges = 1
2443
2442
else :
2444
2443
showedges = 0
@@ -2910,15 +2909,27 @@ def get_position(self):
2910
2909
'Return the axes rectangle left, bottom, width, height'
2911
2910
return [val .get () for val in self ._position ]
2912
2911
2913
- def set_position (self , pos ):
2912
+ def set_position (self , pos , which = 'both' ):
2914
2913
"""
2915
2914
Set the axes position with pos = [left, bottom, width, height]
2916
2915
in relative 0,1 coords
2917
2916
2917
+ There are two position variables: one which is ultimately
2918
+ used, but which may be modified by apply_aspect, and a second
2919
+ which is the starting point for apply_aspect.
2920
+
2921
+ which = 'active' to change the first;
2922
+ 'original' to change the second;
2923
+ 'both' to change both
2924
+
2918
2925
ACCEPTS: len(4) sequence of floats
2919
2926
"""
2920
- for num ,val in zip (pos , self ._position ):
2921
- val .set (num )
2927
+ if which in ('both' , 'active' ):
2928
+ # Change values within self._position--don't replace it.
2929
+ for num ,val in zip (pos , self ._position ):
2930
+ val .set (num )
2931
+ if which in ('both' , 'original' ):
2932
+ self ._originalPosition = pos
2922
2933
2923
2934
def stem (self , x , y , linefmt = 'b-' , markerfmt = 'bo' , basefmt = 'r-' ):
2924
2935
"""
@@ -3948,25 +3959,24 @@ def dist(a):
3948
3959
ds .sort ()
3949
3960
return ds [0 ][1 ]
3950
3961
3951
- def set_aspect (self , aspect = 'auto' , fixLimits = None ,
3952
- aspect_adjusts = 'position' ):
3962
+ def set_aspect (self , aspect = 'auto' , adjusts = 'position' ):
3953
3963
"""
3954
3964
aspect:
3955
3965
'auto' - automatic; fill position rectangle with data
3956
3966
'normal' - same as 'auto'; deprecated
3957
3967
'equal' - same scaling from data to plot units for x and y
3958
- A - a circle will be stretched such that the height
3959
- is A times the width. aspect=1 is the same as
3968
+ num - a circle will be stretched such that the height
3969
+ is num times the width. aspect=1 is the same as
3960
3970
aspect='equal'.
3961
3971
3962
- aspect_adjusts :
3972
+ adjusts :
3963
3973
'position' - change width or height of bounding rectangle;
3964
3974
keep it centered.
3965
3975
'box_size' - as above, but anchored to lower left
3966
3976
'datalim' - change xlim or ylim
3967
3977
3968
- fixLimits: deprecated; False is aspect_adjusts='datalim';
3969
- True is aspect_adjusts='position'
3978
+ Note: the 'adjusts' argument is a convenience; it can be set
3979
+ independently by set_aspect_adjusts.
3970
3980
3971
3981
ACCEPTS: ['auto' | 'equal' | aspect_ratio]
3972
3982
"""
@@ -3977,22 +3987,20 @@ def set_aspect(self, aspect='auto', fixLimits=None,
3977
3987
else :
3978
3988
self ._aspect = float (aspect ) # raise ValueError if necessary
3979
3989
3980
- if fixLimits is not None :
3981
- if not fixLimits : aspect_adjusts = 'datalim'
3982
- if aspect_adjusts in ('position' , 'box_size' , 'datalim' ):
3983
- self ._aspect_adjusts = aspect_adjusts
3990
+ if adjusts in ('position' , 'box_size' , 'datalim' ):
3991
+ self ._aspect_adjusts = adjusts
3984
3992
else :
3985
3993
raise ValueError (
3986
- 'aspect_adjusts must be "position", "box_size", or "datalim"' )
3994
+ 'adjusts must be "position", "box_size", or "datalim"' )
3987
3995
3988
- def set_aspect_adjusts (self , aspect_adjusts = 'position' ):
3996
+ def set_aspect_adjusts (self , adjusts = 'position' ):
3989
3997
"""
3990
3998
Must be called after set_aspect.
3991
3999
3992
4000
ACCEPTS: ['position' | 'box_size' | 'datalim']
3993
4001
"""
3994
- if aspect_adjusts in ('position' , 'box_size' , 'datalim' ):
3995
- self ._aspect_adjusts = aspect_adjusts
4002
+ if adjusts in ('position' , 'box_size' , 'datalim' ):
4003
+ self ._aspect_adjusts = adjusts
3996
4004
else :
3997
4005
raise ValueError (
3998
4006
'argument must be "position", "box_size", or "datalim"' )
@@ -4005,7 +4013,7 @@ def apply_aspect(self):
4005
4013
'''
4006
4014
4007
4015
if self ._aspect == 'auto' :
4008
- self .set_position ( self ._originalPosition )
4016
+ self .set_position ( self ._originalPosition , 'active' )
4009
4017
return
4010
4018
4011
4019
if self ._aspect == 'equal' :
@@ -4034,10 +4042,9 @@ def apply_aspect(self):
4034
4042
B = b + 0.5 * (h - H )
4035
4043
else :
4036
4044
L ,B = l ,b
4037
- self .set_position ((L ,B ,W ,H ))
4045
+ self .set_position ((L ,B ,W ,H ), 'active' )
4038
4046
return
4039
4047
4040
- self .autoscale_view ()
4041
4048
xmin ,xmax = self .get_xlim ()
4042
4049
xsize = math .fabs (xmax - xmin )
4043
4050
ymin ,ymax = self .get_ylim ()
0 commit comments