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

Skip to content

Commit fda65b4

Browse files
author
Akshay Nair
committed
Fixes issue #8946
1 parent 79fb398 commit fda65b4

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,12 @@ def set_xticks(self, ticks, minor=False):
32033203
"""
32043204
ret = self.xaxis.set_ticks(ticks, minor=minor)
32053205
self.stale = True
3206+
3207+
g = self.get_shared_x_axes()
3208+
for ax in g.get_siblings(self):
3209+
ax.xaxis.set_ticks(ticks, minor=minor)
3210+
ax.stale = True
3211+
32063212
return ret
32073213

32083214
def get_xmajorticklabels(self):
@@ -3290,6 +3296,12 @@ def set_xticklabels(self, labels, fontdict=None, minor=False, **kwargs):
32903296
ret = self.xaxis.set_ticklabels(labels,
32913297
minor=minor, **kwargs)
32923298
self.stale = True
3299+
3300+
g = self.get_shared_x_axes()
3301+
for ax in g.get_siblings(self):
3302+
ax.xaxis.set_ticklabels(labels, minor=minor, **kwargs)
3303+
ax.stale = True
3304+
32933305
return ret
32943306

32953307
def invert_yaxis(self):
@@ -3521,6 +3533,9 @@ def set_yticks(self, ticks, minor=False):
35213533
Default is ``False``.
35223534
"""
35233535
ret = self.yaxis.set_ticks(ticks, minor=minor)
3536+
g = self.get_shared_y_axes()
3537+
for ax in g.get_siblings(self):
3538+
ax.yaxis.set_ticks(ticks, minor=minor)
35243539
return ret
35253540

35263541
def get_ymajorticklabels(self):
@@ -3605,8 +3620,12 @@ def set_yticklabels(self, labels, fontdict=None, minor=False, **kwargs):
36053620
"""
36063621
if fontdict is not None:
36073622
kwargs.update(fontdict)
3608-
return self.yaxis.set_ticklabels(labels,
3623+
ret = self.yaxis.set_ticklabels(labels,
36093624
minor=minor, **kwargs)
3625+
g = self.get_shared_y_axes()
3626+
for ax in g.get_siblings(self):
3627+
ax.yaxis.set_ticklabels(labels, minor=minor, **kwargs)
3628+
return ret
36103629

36113630
def xaxis_date(self, tz=None):
36123631
"""

lib/matplotlib/tests/test_axes.py

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

51305130

5131+
def test_shared_axes_retick():
5132+
# related to GitHub issue 8946
5133+
# set_xticks should set shared axes limits
5134+
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
5135+
5136+
data = np.random.randn(10)
5137+
data2 = np.random.randn(10)
5138+
index = range(10)
5139+
index2 = [x + 5.5 for x in index]
5140+
5141+
ax_lst[0][0].scatter(index, data)
5142+
ax_lst[0][1].scatter(index2, data2)
5143+
5144+
ax_lst[1][0].scatter(index, data)
5145+
ax_lst[1][1].scatter(index2, data2)
5146+
5147+
ax_lst[0][0].set_xticks(range(-10, 20, 1))
5148+
ax_lst[0][0].set_yticks(range(-10, 20, 1))
5149+
5150+
assert ax_lst[0][0].get_xlim() == ax_lst[0][1].get_xlim()
5151+
assert ax_lst[0][0].get_ylim() == ax_lst[1][0].get_ylim()
5152+
5153+
51315154
def test_adjust_numtick_aspect():
51325155
fig, ax = plt.subplots()
51335156
ax.yaxis.get_major_locator().set_params(nbins='auto')

0 commit comments

Comments
 (0)