Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 5 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,10 +1061,11 @@ def set_position(self, pos, which='both'):
matplotlib.transforms.Bbox.from_bounds
matplotlib.transforms.Bbox.from_extents
"""
self._set_position(pos, which=which)
# because this is being called externally to the library we
# don't let it be in the layout.
self.set_in_layout(False)
for ax in self._twinned_axes.get_siblings(self):
ax._set_position(pos, which=which)
# because this is being called externally to the library we
# don't let it be in the layout.
ax.set_in_layout(False)

def _set_position(self, pos, which='both'):
"""
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ def test_twinx_axis_scales():
ax2.margins(0, 0)


@pytest.mark.parametrize('twin', ('x', 'y'))
def test_twin_moved(twin):
fig, ax = plt.subplots()
# test twinx or twiny
ax_twin = getattr(ax, f'twin{twin}')()
ax.set_position([0.2, 0.2, 0.5, 0.5])
fig.draw_without_rendering()

assert_array_equal(ax.bbox.extents,
ax_twin.bbox.extents)


def test_twin_inherit_autoscale_setting():
fig, ax = plt.subplots()
ax_x_on = ax.twinx()
Expand Down