8000 Merge pull request #10798 from shaynair/issue-10062-dev · tomspur/matplotlib@6466bfa · GitHub
[go: up one dir, main page]

Skip to content

Commit 6466bfa

Browse files
authored
Merge pull request matplotlib#10798 from shaynair/issue-10062-dev
FIX: axes limits reverting to automatic when sharing
2 parents ffe6021 + 7ad9801 commit 6466bfa

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,8 @@ def cla(self):
991991
self.xaxis.major = self._sharex.xaxis.major
992992
self.xaxis.minor = self._sharex.xaxis.minor
993993
x0, x1 = self._sharex.get_xlim()
994-
self.set_xlim(x0, x1, emit=False, auto=None)
994+
self.set_xlim(x0, x1, emit=False,
995+
auto=self._sharex.get_autoscalex_on())
995996
self.xaxis._scale = mscale.scale_factory(
996997
self._sharex.xaxis.get_scale(), self.xaxis)
997998
else:
@@ -1005,7 +1006,8 @@ def cla(self):
10051006
self.yaxis.major = self._sharey.yaxis.major
10061007
self.yaxis.minor = self._sharey.yaxis.minor
10071008
y0, y1 = self._sharey.get_ylim()
1008-
self.set_ylim(y0, y1, emit=False, auto=None)
1009+
self.set_ylim(y0, y1, emit=False,
1010+
auto=self._sharey.get_autoscaley_on())
10091011
self.yaxis._scale = mscale.scale_factory(
10101012
self._sharey.yaxis.get_scale(), self.yaxis)
10111013
else:
@@ -1021,8 +1023,10 @@ def cla(self):
10211023
if (rcParams['ytick.minor.visible']):
10221024
self.yaxis.set_minor_locator(mticker.AutoMinorLocator())
10231025

1024-
self._autoscaleXon = True
1025-
self._autoscaleYon = True
1026+
if self._sharex is None:
1027+
self._autoscaleXon = True
1028+
if self._sharey is None:
1029+
self._autoscaleYon = True
10261030
self._xmargin = rcParams['axes.xmargin']
10271031
self._ymargin = rcParams['axes.ymargin']
10281032
self._tight = None

lib/matplotlib/tests/test_axes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5134,6 +5134,23 @@ def test_remove_shared_axes_relim():
51345134
assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
51355135

51365136

5137+
def test_shared_axes_autoscale():
5138+
l = np.arange(-80, 90, 40)
5139+
t = np.random.random_sample((l.size, l.size))
5140+
5141+
ax1 = plt.subplot(211)
5142+
ax1.set_xlim(-1000, 1000)
5143+
ax1.set_ylim(-1000, 1000)
5144+
ax1.contour(l, l, t)
5145+
5146+
ax2 = plt.subplot(212, sharex=ax1, sharey=ax1)
5147+
ax2.contour(l, l, t)
5148+
assert not ax1.get_autoscalex_on() and not ax2.get_autoscalex_on()
5149+
assert not ax1.get_autoscaley_on() and not ax2.get_autoscaley_on()
5150+
assert ax1.get_xlim() == ax2.get_xlim() == (-1000, 1000)
5151+
assert ax1.get_ylim() == ax2.get_ylim() == (-1000, 1000)
5152+
5153+
51375154
def test_adjust_numtick_aspect():
51385155
fig, ax = plt.subplots()
51395156
ax.yaxis.get_major_locator().set_params(nbins='auto')

0 commit comments

Comments
 (0)
0