Skip to content

Commit b01c31d

Browse files
committed
twinx and twiny inherit autoscale setting for shared axis from parent Axes
1 parent b1e0937 commit b01c31d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,7 @@ def twinx(self):
39243924
ax2.yaxis.tick_right()
39253925
ax2.yaxis.set_label_position('right')
39263926
ax2.yaxis.set_offset_position('right')
3927+
ax2.set_autoscalex_on(self.get_autoscalex_on())
39273928
self.yaxis.tick_left()
39283929
ax2.xaxis.set_visible(False)
39293930
ax2.patch.set_visible(False)
@@ -3952,6 +3953,7 @@ def twiny(self):
39523953
ax2 = self._make_twin_axes(sharey=self)
39533954
ax2.xaxis.tick_top()
39543955
ax2.xaxis.set_label_position('top')
3956+
ax2.set_autoscaley_on(self.get_autoscaley_on())
39553957
self.xaxis.tick_bottom()
39563958
ax2.yaxis.set_visible(False)
39573959
ax2.patch.set_visible(False)

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ def test_twinx_cla():
145145
assert ax.yaxis.get_visible()
146146

147147

148+
@cleanup
149+
def test_twin_inherit_autoscale():
150+
fig, ax = plt.subplots()
151+
ax_x_on = ax.twinx()
152+
ax.set_autoscalex_on(False)
153+
ax_x_off = ax.twinx()
154+
155+
assert ax_x_on.get_autoscalex_on()
156+
assert not ax_x_off.get_autoscalex_on()
157+
158+
ax_y_on = ax.twiny()
159+
ax.set_autoscaley_on(False)
160+
ax_y_off = ax.twiny()
161+
162+
assert ax_y_on.get_autoscaley_on()
163+
assert not ax_y_off.get_autoscaley_on()
164+
165+
148166
@image_comparison(baseline_images=["minorticks_on_rcParams_both"], extensions=['png'])
149167
def test_minorticks_on_rcParams_both():
150168
fig = plt.figure()

0 commit comments

Comments
 (0)