@@ -490,25 +490,15 @@ def __init__(self, fig, rect,
490
490
self ._originalPosition = self ._position .frozen ()
491
491
# self.set_axes(self)
492
492
self .axes = self
493
- self .set_aspect ( 'auto' )
493
+ self ._aspect = 'auto'
494
494
self ._adjustable = 'box'
495
- self .set_anchor ( 'C' )
495
+ self ._anchor = 'C'
496
496
self ._sharex = sharex
497
497
self ._sharey = sharey
498
498
if sharex is not None :
499
499
self ._shared_x_axes .join (self , sharex )
500
- if sharex ._adjustable == 'box' :
501
- sharex ._adjustable = 'datalim'
502
- # warnings.warn(
503
- # 'shared axes: "adjustable" is being changed to "datalim"')
504
- self ._adjustable = 'datalim'
505
500
if sharey is not None :
506
501
self ._shared_y_axes .join (self , sharey )
507
- if sharey ._adjustable == 'box' :
508
- sharey ._adjustable = 'datalim'
509
- # warnings.warn(
510
- # 'shared axes: "adjustable" is being changed to "datalim"')
511
- self ._adjustable = 'datalim'
512
502
self .set_label (label )
513
503
self .set_figure (fig )
514
504
@@ -532,6 +522,7 @@ def __init__(self, fig, rect,
532
522
533
523
self ._connected = {} # a dict from events to (id, func)
534
524
self .cla ()
525
+
535
526
# funcs used to format x and y - fall back on major formatters
536
527
self .fmt_xdata = None
537
528
self .fmt_ydata = None
@@ -633,8 +624,7 @@ def set_figure(self, fig):
633
624
634
625
def _set_lim_and_transforms (self ):
635
626
"""
636
- set the *dataLim* and *viewLim*
637
- :class:`~matplotlib.transforms.Bbox` attributes and the
627
+ set the *_xaxis_transform*, *_yaxis_transform*,
638
628
*transScale*, *transData*, *transLimits* and *transAxes*
639
629
transformations.
640
630
@@ -984,21 +974,22 @@ def cla(self):
984
974
985
975
self .xaxis .cla ()
986
976
self .yaxis .cla ()
977
+
987
978
for name , spine in six .iteritems (self .spines ):
988
979
spine .cla ()
989
980
990
981
self .ignore_existing_data_limits = True
991
982
self .callbacks = cbook .CallbackRegistry ()
992
983
993
984
if self ._sharex is not None :
994
- # major and minor are class instances with
985
+ # major and minor are axis.Ticker class instances with
995
986
# locator and formatter attributes
996
987
self .xaxis .major = self ._sharex .xaxis .major
997
988
self .xaxis .minor = self ._sharex .xaxis .minor
998
989
x0 , x1 = self ._sharex .get_xlim ()
999
990
self .set_xlim (x0 , x1 , emit = False , auto = None )
1000
991
self .xaxis ._scale = mscale .scale_factory (
1001
- self ._sharex .xaxis .get_scale (), self .xaxis )
992
+ self ._sharex .xaxis .get_scale (), self .xaxis )
1002
993
else :
1003
994
self .xaxis ._set_scale ('linear' )
1004
995
try :
@@ -1012,14 +1003,13 @@ def cla(self):
1012
1003
y0 , y1 = self ._sharey .get_ylim ()
1013
1004
self .set_ylim (y0 , y1 , emit = False , auto = None )
1014
1005
self .yaxis ._scale = mscale .scale_factory (
1015
- self ._sharey .yaxis .get_scale (), self .yaxis )
1006
+ self ._sharey .yaxis .get_scale (), self .yaxis )
1016
1007
else :
1017
1008
self .yaxis ._set_scale ('linear' )
1018
1009
try :
1019
1010
self .set_ylim (0 , 1 )
1020
1011
except TypeError :
1021
1012
pass
1022
-
1023
1013
# update the minor locator for x and y axis based on rcParams
1024
1014
if (rcParams ['xtick.minor.visible' ]):
1025
1015
self .xaxis .set_minor_locator (mticker .AutoMinorLocator ())
@@ -1262,7 +1252,7 @@ def hold(self, b=None):
1262
1252
def get_aspect (self ):
1263
1253
return self ._aspect
1264
1254
1265
- def set_aspect (self , aspect , adjustable = None , anchor = None ):
1255
+ def set_aspect (self , aspect , adjustable = None , anchor = None , share = False ):
1266
1256
"""
1267
1257
Set the aspect of the axis scaling, i.e. the ratio of y-unit to x-unit.
1268
1258
@@ -1281,7 +1271,7 @@ def set_aspect(self, aspect, adjustable=None, anchor=None):
1281
1271
aspect='equal'.
1282
1272
======== ================================================
1283
1273
1284
- adjustable : None or ['box' | 'datalim' | 'box-forced' ], optional
1274
+ adjustable : None or ['box' | 'datalim'], optional
1285
1275
If not ``None``, this defines which parameter will be adjusted to
1286
1276
meet the required aspect. See `.set_adjustable` for further
1287
1277
details.
@@ -1317,16 +1307,25 @@ def set_aspect(self, aspect, adjustable=None, anchor=None):
1317
1307
else :
1318
1308
self ._aspect = float (aspect ) # raise ValueError if necessary
1319
1309
1320
- if adjustable is not None :
1321
- self .set_adjustable (adjustable )
1310
+ if share and self in self ._shared_x_axes :
1311
+ for ax in self ._shared_x_axes .get_siblings (self ):
1312
+ ax ._aspect = aspect
1313
+ if share and self in self ._shared_y_axes :
1314
+ for ax in self ._shared_y_axes .get_siblings (self ):
1315
+ ax ._aspect = aspect
1316
+
1317
+ if adjustable is None :
1318
+ adjustable = self ._adjustable
1319
+ self .set_adjustable (adjustable , share = share ) # Handle sharing.
1320
+
1322
1321
if anchor is not None :
1323
1322
self .set_anchor (anchor )
1324
1323
self .stale = True
1325
1324
1326
1325
def get_adjustable (self ):
1327
1326
return self ._adjustable
1328
1327
1329
- def set_adjustable (self , adjustable ):
1328
+ def set_adjustable (self , adjustable , share = False ):
1330
1329
"""
1331
1330
Define which parameter the Axes will change to achieve a given aspect.
1332
1331
@@ -1337,26 +1336,28 @@ def set_adjustable(self, adjustable):
1337
1336
============ =====================================
1338
1337
'box' change the physical size of the Axes
1339
1338
'datalim' change xlim or ylim
1340
- 'box-forced' same as 'box', but axes can be shared
1341
1339
============ =====================================
1342
1340
1343
- 'box' does not allow axes sharing, as this can cause
1344
- unintended side effect. For cases when sharing axes is
1345
- fine, use 'box-forced'.
1346
-
1347
1341
..
1348
- ACCEPTS: [ 'box' | 'datalim' | 'box-forced' ]
1342
+ ACCEPTS: [ 'box' | 'datalim']
1349
1343
1350
1344
See Also
1351
1345
--------
1352
1346
matplotlib.axes.Axes.set_aspect
1353
1347
for a description of aspect handling.
1354
1348
"""
1349
+ # FIXME: add box-forced deprecation
1355
1350
if adjustable in ('box' , 'datalim' , 'box-forced' ):
1356
- if self in self ._shared_x_axes or self in self ._shared_y_axes :
1357
- if adjustable == 'box ' :
1351
+ if self in self ._shared_x_axes and self in self ._shared_y_axes :
1352
+ if adjustable == 'datalim ' :
1358
1353
raise ValueError (
1359
- 'adjustable must be "datalim" for shared axes' )
1354
+ 'adjustable must be "box" when both axes are shared' )
1355
+ if share and self in self ._shared_x_axes :
1356
+ for ax in self ._shared_x_axes .get_siblings (self ):
1357
+ ax ._adjustable = adjustable
1358
+ if share and self in self ._shared_y_axes :
1359
+ for ax in self ._shared_y_axes .get_siblings (self ):
1360
+ ax ._adjustable = adjustable
1360
1361
self ._adjustable = adjustable
1361
1362
else :
1362
1363
raise ValueError ('argument must be "box", or "datalim"' )
@@ -1508,14 +1509,6 @@ def apply_aspect(self, position=None):
1508
1509
else :
1509
1510
A = aspect
1510
1511
1511
- # Ensure at drawing time that any Axes involved in axis-sharing
1512
- # does not have its position changed.
1513
- if self in self ._shared_x_axes or self in self ._shared_y_axes :
1514
- if self ._adjustable == 'box' :
1515
- self ._adjustable = 'datalim'
1516
- warnings .warn (
1517
- 'shared axes: "adjustable" is being changed to "datalim"' )
1518
-
1519
1512
figW , figH = self .get_figure ().get_size_inches ()
1520
1513
fig_aspect = figH / figW
1521
1514
if self ._adjustable in ['box' , 'box-forced' ]:
@@ -1573,23 +1566,24 @@ def apply_aspect(self, position=None):
1573
1566
xm = 0
1574
1567
ym = 0
1575
1568
1576
- changex = ( self in self ._shared_y_axes and
1577
- self not in self ._shared_x_axes )
1578
- changey = ( self in self . _shared_x_axes and
1579
- self not in self . _shared_y_axes )
1580
- if changex and changey :
1581
- warnings . warn ( "adjustable='datalim' cannot work with shared "
1582
- "x and y axes" )
1583
- return
1584
- if changex :
1569
+ shared_x = self in self ._shared_x_axes
1570
+ shared_y = self in self ._shared_y_axes
1571
+ # Not sure whether we need this check:
1572
+ if shared_x and shared_y :
1573
+ raise RuntimeError ( "adjustable='datalim' is not allowed when both"
1574
+ " axes are shared." )
1575
+
1576
+ # If y is shared, then we are only allowed to change x, etc.
1577
+ if shared_y :
1585
1578
adjust_y = False
1586
1579
else :
1587
1580
if xmarg > xm and ymarg > ym :
1588
1581
adjy = ((Ymarg > 0 and y_expander < 0 ) or
1589
1582
(Xmarg < 0 and y_expander > 0 ))
1590
1583
else :
1591
1584
adjy = y_expander > 0
1592
- adjust_y = changey or adjy # (Ymarg > xmarg)
1585
+ adjust_y = shared_x or adjy # (Ymarg > xmarg)
1586
+
1593
1587
if adjust_y :
1594
1588
yc = 0.5 * (ymin + ymax )
1595
1589
y0 = yc - Ysize / 2.0
@@ -4189,9 +4183,9 @@ def twiny(self):
4189
4183
return ax2
4190
4184
4191
4185
def get_shared_x_axes (self ):
4192
- """ Return a copy of the shared axes Grouper object for x axes."""
4186
+ ' Return a reference to the shared axes Grouper object for x axes'
4193
4187
return self ._shared_x_axes
4194
4188
4195
4189
def get_shared_y_axes (self ):
4196
- """ Return a copy of the shared axes Grouper object for y axes."""
4190
+ ' Return a reference to the shared axes Grouper object for y axes'
4197
4191
return self ._shared_y_axes
0 commit comments