Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9e1c69

Browse files
committed
Simplifications and docstring improvements
1 parent 2f6147f commit e9e1c69

File tree

1 file changed

+45
-46
lines changed

1 file changed

+45
-46
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -875,10 +875,7 @@ def set_position(self, pos, which='both'):
875875
"""
876876
if not isinstance(pos, mtransforms.BboxBase):
877877
pos = mtransforms.Bbox.from_bounds(*pos)
878-
twins = self._twinned_axes.get_siblings(self)
879-
if not twins:
880-
twins = [self]
881-
for ax in twins:
878+
for ax in self._twinned_axes.get_siblings(self):
882879
if which in ('both', 'active'):
883880
ax._position.set(pos)
884881
if which in ('both', 'original'):
@@ -892,10 +889,7 @@ def reset_position(self):
892889
This resets the a possible position change due to aspect constraints.
893890
For an explanation of the positions see `.set_position`.
894891
"""
895-
twins = self._twinned_axes.get_siblings(self)
896-
if not twins:
897-
twins = [self]
898-
for ax in twins:
892+
for ax in self._twinned_axes.get_siblings(self):
899893
pos = ax.get_position(original=True)
900894
ax.set_position(pos, which='active')
901895

@@ -1302,6 +1296,10 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
13021296
13031297
See `.set_anchor` for further details.
13041298
1299+
share : bool, optional
1300+
If ``True``, apply the settings to all shared Axes.
1301+
Default is ``False``.
1302+
13051303
See Also
13061304
--------
13071305
matplotlib.axes.Axes.set_adjustable
@@ -1310,25 +1308,23 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
13101308
matplotlib.axes.Axes.set_anchor
13111309
defining the position in case of extra space.
13121310
"""
1313-
if (isinstance(aspect, six.string_types)
1311+
if not (isinstance(aspect, six.string_types)
13141312
and aspect in ('equal', 'auto')):
1315-
self._aspect = aspect
1313+
aspect = float(aspect) # raise ValueError if necessary
1314+
if share:
1315+
axes = set(self._shared_x_axes.get_siblings(self)
1316+
+ self._shared_y_axes.get_siblings(self))
13161317
else:
1317-
self._aspect = float(aspect) # raise ValueError if necessary
1318-
1319-
if share and self in self._shared_x_axes:
1320-
for ax in self._shared_x_axes.get_siblings(self):
1321-
ax._aspect = aspect
1322-
if share and self in self._shared_y_axes:
1323-
for ax in self._shared_y_axes.get_siblings(self):
1324-
ax._aspect = aspect
1318+
axes = [self]
1319+
for ax in axes:
1320+
ax._aspect = aspect
13251321

13261322
if adjustable is None:
13271323
adjustable = self._adjustable
13281324
self.set_adjustable(adjustable, share=share) # Handle sharing.
13291325

13301326
if anchor is not None:
1331-
self.set_anchor(anchor)
1327+
self.set_anchor(anchor) # Also needs a "share" kwarg?
13321328
self.stale = True
13331329

13341330
def get_adjustable(self):
@@ -1338,14 +1334,15 @@ def set_adjustable(self, adjustable, share=False):
13381334
"""
13391335
Define which parameter the Axes will change to achieve a given aspect.
13401336
1341-
Possible values are:
1337+
Parameters
1338+
----------
1339+
adjustable : ['box' | 'datalim']
1340+
If 'box', change the physical dimensions of the Axes.
1341+
If 'datalim', change the ``x`` or ``y`` data limits.
13421342
1343-
============ =====================================
1344-
value description
1345-
============ =====================================
1346-
'box' change the physical size of the Axes
1347-
'datalim' change xlim or ylim
1348-
============ =====================================
1343+
share : bool, optional
1344+
If ``True``, apply the settings to all shared Axes.
1345+
Default is ``False``.
13491346
13501347
..
13511348
ACCEPTS: [ 'box' | 'datalim']
@@ -1355,17 +1352,18 @@ def set_adjustable(self, adjustable, share=False):
13551352
matplotlib.axes.Axes.set_aspect
13561353
for a description of aspect handling.
13571354
"""
1358-
# FIXME: add box-forced deprecation
1359-
if adjustable in ('box', 'datalim', 'box-forced'):
1360-
if share and self in self._shared_x_axes:
1361-
for ax in self._shared_x_axes.get_siblings(self):
1362-
ax._adjustable = adjustable
1363-
if share and self in self._shared_y_axes:
1364-
for ax in self._shared_y_axes.get_siblings(self):
1365-
ax._adjustable = adjustable
1366-
self._adjustable = adjustable
1355+
if adjustable == 'box-forced':
1356+
warnings.warn("The 'box-forced' keyword argument is deprecated"
1357+
" since 2.2.", mplDeprecation)
1358+
if adjustable not in ('box', 'datalim', 'box-forced'):
1359+
raise ValueError("argument must be 'box', or 'datalim'")
1360+
if share:
1361+
axes = set(self._shared_x_axes.get_siblings(self)
1362+
+ self._shared_y_axes.get_siblings(self))
13671363
else:
1368-
raise ValueError('argument must be "box", or "datalim"')
1364+
axes = [self]
1365+
for ax in axes:
1366+
ax._adjustable = adjustable
13691367
self.stale = True
13701368

13711369
def get_anchor(self):
@@ -1461,21 +1459,22 @@ def get_data_ratio_log(self):
14611459

14621460
def apply_aspect(self, position=None):
14631461
"""
1464-
Adjust the Axes so that it fulfills its aspect setting.
1462+
Adjust the Axes for a specified data aspect ratio.
14651463
1466-
Depending on `.get_adjustable` and `.get_anchor` this will either
1467-
modify the Axes box or the view limits.
1464+
Depending on `.get_adjustable` this will modify either the Axes box
1465+
(position) or the view limits. In the former case, `.get_anchor`
1466+
will affect the position.
14681467
14691468
Notes
14701469
-----
1471-
This is automatically called on draw. So you won't need to call this
1472-
yourself in most cases. One exception may be if you need to update the
1473-
Axes before drawing.
1470+
This is called automatically when each Axes is drawn. You may need
1471+
to call it yourself if you need to update the Axes position and/or
1472+
view limits before the Figure is drawn.
14741473
14751474
See Also
14761475
--------
14771476
matplotlib.axes.Axes.set_aspect
1478-
for a description of aspect handling.
1477+
for a description of aspect ratio handling.
14791478
matplotlib.axes.Axes.set_adjustable
14801479
defining the parameter to adjust in order to meet the required
14811480
aspect.
@@ -4127,9 +4126,9 @@ def _make_twin_axes(self, *kl, **kwargs):
41274126
"""
41284127
# Typically, SubplotBase._make_twin_axes is called instead of this.
41294128
ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs)
4130-
# do not touch every thing shared, just this and it's twin.
4131-
self.set_adjustable('datalim')
4132-
ax2.set_adjustable('datalim')
4129+
## do not touch every thing shared, just this and it's twin.
4130+
#self.set_adjustable('datalim')
4131+
#ax2.set_adjustable('datalim')
41334132
self._twinned_axes.join(self, ax2)
41344133
return ax2
41354134

0 commit comments

Comments
 (0)