Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3fd1727

Browse files
author
Akshay Nair
committed
Fix for issue #10062
1 parent 2898bfa commit 3fd1727

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,8 @@ def cla(self):
10151015
self.xaxis.major = self._sharex.xaxis.major
10161016
self.xaxis.minor = self._sharex.xaxis.minor
10171017
x0, x1 = self._sharex.get_xlim()
1018-
self.set_xlim(x0, x1, emit=False, auto=None)
1018+
self.set_xlim(x0, x1, emit=False,
1019+
auto=self._sharex.get_autoscalex_on())
10191020
self.xaxis._scale = mscale.scale_factory(
10201021
self._sharex.xaxis.get_scale(), self.xaxis)
10211022
else:
@@ -1029,7 +1030,8 @@ def cla(self):
10291030
self.yaxis.major = self._sharey.yaxis.major
10301031
self.yaxis.minor = self._sharey.yaxis.minor
10311032
y0, y1 = self._sharey.get_ylim()
1032-
self.set_ylim(y0, y1, emit=False, auto=None)
1033+
self.set_ylim(y0, y1, emit=False,
1034+
auto=self._sharey.get_autoscaley_on())
10331035
self.yaxis._scale = mscale.scale_factory(
10341036
self._sharey.yaxis.get_scale(), self.yaxis)
10351037
else:
@@ -1045,8 +1047,10 @@ def cla(self):
10451047
if (rcParams['ytick.minor.visible']):
10461048
self.yaxis.set_minor_locator(mticker.AutoMinorLocator())
10471049

1048-
self._autoscaleXon = True
1049-
self._autoscaleYon = True
1050+
if self._sharex is None:
1051+
self._autoscaleXon = True
1052+
if self._sharey is None:
1053+
self._autoscaleYon = True
10501054
self._xmargin = rcParams['axes.xmargin']
10511055
self._ymargin = rcParams['axes.ymargin']
10521056
self._tight = None

lib/matplotlib/tests/test_axes.py

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

51295129

5130+
def test_shared_axes_autoscale():
5131+
l = np.arange(-80,90,40)
5132+
t = np.random.random_sample((l.size,l.size))
5133+
5134+
ax1 = plt.subplot(211)
5135+
ax1.set_xlim(-1000,1000)
5136+
ax1.set_ylim(-1000,1000)
5137+
ax1.contour(l,l,t)
5138+
5139+
ax2 = plt.subplot(212,sharex=ax1,sharey=ax1)
5140+
ax2.contour(l,l,t)
5141+
assert not ax1.get_autoscalex_on() and not ax2.get_autoscalex_on()
5142+
assert not ax1.get_autoscaley_on() and not ax2.get_autoscaley_on()
5143+
assert ax1.get_xlim() == ax2.get_xlim() == (-1000, 1000)
5144+
assert ax1.get_ylim() == ax2.get_ylim() == (-1000, 1000)
5145+
5146+
51305147
def test_adjust_numtick_aspect():
51315148
fig, ax = plt.subplots()
51325149
ax.yaxis.get_major_locator().set_params(nbins='auto')

0 commit comments

Comments
 (0)