Skip to content

Commit ed9b984

Browse files
committed
twinx and twiny inherit autoscale setting for shared axis from parent Axes
1 parent 59478d2 commit ed9b984

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,8 +3924,10 @@ 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)
3930+
ax2.set
39293931
ax2.patch.set_visible(False)
39303932
return ax2
39313933

@@ -3952,6 +3954,7 @@ def twiny(self):
39523954
ax2 = self._make_twin_axes(sharey=self)
39533955
ax2.xaxis.tick_top()
39543956
ax2.xaxis.set_label_position('top')
3957+
ax2.set_autoscaley_on(self.get_autoscaley_on())
39553958
self.xaxis.tick_bottom()
39563959
ax2.yaxis.set_visible(False)
39573960
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)