Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
API: re-allow 'datalim' as a valid adjustable with shared axes
This is to allow twinx and twiny to work as expected.
  • Loading branch information
tacaswell committed Jul 2, 2017
commit 7dba6868b10a722b37f7ba0d1fc119d9b8a233de
9 changes: 4 additions & 5 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def __init__(self, fig, rect,
================ =========================================
Keyword Description
================ =========================================
*adjustable* [ 'box' | 'datalim' | 'box-forced']
*adjustable* [ 'box' | 'datalim' ]
*alpha* float: the alpha transparency (can be None)
*anchor* [ 'C', 'SW', 'S', 'SE', 'E', 'NE', 'N',
'NW', 'W' ]
Expand Down Expand Up @@ -1286,10 +1286,6 @@ def set_adjustable(self, adjustable, share=False):
"""
# FIXME: add box-forced deprecation
if adjustable in ('box', 'datalim', 'box-forced'):
if self in self._shared_x_axes and self in self._shared_y_axes:
if adjustable == 'datalim':
raise ValueError(
'adjustable must be "box" when both axes are shared')
if share and self in self._shared_x_axes:
for ax in self._shared_x_axes.get_siblings(self):
ax._adjustable = adjustable
Expand Down Expand Up @@ -3916,6 +3912,9 @@ def _make_twin_axes(self, *kl, **kwargs):
make a twinx axes of self. This is used for twinx and twiny.
"""
ax2 = self.figure.add_axes(self.get_position(True), *kl, **kwargs)
# do not touch every thing shared, just this and it's twin.
self.set_adjustable('datalim')
ax2.set_adjustable('datalim')
return ax2

def twinx(self):
Expand Down
13 changes: 11 additions & 2 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4240,8 +4240,6 @@ def test_shared_with_aspect():
plt.draw() # Trigger apply_aspect().
assert axes[0].get_xlim() == axes[1].get_xlim()
assert axes[0].get_ylim() == axes[1].get_ylim()
with pytest.raises(ValueError):
axes[0].set_aspect(1, adjustable='datalim', share=True)

# Different aspect ratios:
for adjustable in ['box', 'datalim']:
Expand All @@ -4262,6 +4260,17 @@ def test_shared_with_aspect():
assert round(expected, 4) == round(ax.get_aspect(), 4)


@pytest.mark.parametrize('twin', ('x', 'y'))
def test_twin_with_aspect(twin):
fig, ax = plt.subplots()
# test twinx or twiny
ax_twin = getattr(ax, 'twin{}'.format(twin))()
ax.set_aspect(5)
ax_twin.set_aspect(2)
assert_array_equal(ax.bbox.extents,
ax_twin.bbox.extents)


def test_relim_visible_only():
x1 = (0., 10.)
y1 = (0., 10.)
Expand Down