Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef0dd78

Browse filesBrowse files
committed
FIX: update scale on shared axes
Fixes #4450 Or at least the scary part of the scale change not propagating to all shared axes.
1 parent 7285c4c commit ef0dd78
Copy full SHA for ef0dd78

File tree

Expand file treeCollapse file tree

2 files changed

+39
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+39
-10
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,10 +2673,13 @@ def set_xscale(self, value, **kwargs):
26732673
# around zero
26742674
if value.lower() == 'log' and 'nonposx' not in kwargs.keys():
26752675
kwargs['nonposx'] = 'clip'
2676-
self.xaxis._set_scale(value, **kwargs)
2677-
self.autoscale_view(scaley=False)
2678-
self._update_transScale()
2679-
self.stale = True
2676+
2677+
g = self.get_shared_x_axes()
2678+
for ax in g.get_siblings(self):
2679+
ax.xaxis._set_scale(value, **kwargs)
2680+
ax.autoscale_view(scaley=False)
2681+
ax._update_transScale()
2682+
ax.stale = True
26802683

26812684
def get_xticks(self, minor=False):
26822685
"""Return the x ticks as a list of locations"""
@@ -2926,10 +2929,13 @@ def set_yscale(self, value, **kwargs):
29262929
# around zero
29272930
if value.lower() == 'log' and 'nonposy' not in kwargs.keys():
29282931
kwargs['nonposy'] = 'clip'
2929-
self.yaxis._set_scale(value, **kwargs)
2930-
self.autoscale_view(scalex=False)
2931-
self._update_transScale()
2932-
self.stale = True
2932+
2933+
g = self.get_shared_y_axes()
2934+
for ax in g.get_siblings(self):
2935+
ax.yaxis._set_scale(value, **kwargs)
2936+
ax.autoscale_view(scalex=False)
2937+
ax._update_transScale()
2938+
ax.stale = True
29332939

29342940
def get_yticks(self, minor=False):
29352941
"""Return the y ticks as a list of locations"""

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+25-2Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3796,8 +3796,9 @@ def test_rc_spines():
37963796
with matplotlib.rc_context(rc_dict):
37973797
fig, ax = plt.subplots()
37983798

3799+
37993800
@image_comparison(baseline_images=['rc_grid'], extensions=['png'],
3800-
savefig_kwarg={'dpi':40})
3801+
savefig_kwarg={'dpi': 40})
38013802
def test_rc_grid():
38023803
fig = plt.figure()
38033804
rc_dict0 = {
@@ -3811,11 +3812,13 @@ def test_rc_grid():
38113812
}
38123813
dict_list = [rc_dict0, rc_dict1, rc_dict2]
38133814

3814-
i=1
3815+
i = 1
38153816
for rc_dict in dict_list:
38163817
with matplotlib.rc_context(rc_dict):
38173818
fig.add_subplot(3, 1, i)
38183819
i += 1
3820+
3821+
38193822
@cleanup
38203823
def test_bar_negative_width():
38213824
fig, ax = plt.subplots()
@@ -3826,6 +3829,7 @@ def test_bar_negative_width():
38263829
assert_equal(b._width, 1)
38273830
assert_equal(b._height, indx + 1)
38283831

3832+
38293833
@cleanup
38303834
def test_square_plot():
38313835
x = np.arange(4)
@@ -3837,6 +3841,7 @@ def test_square_plot():
38373841
assert_true(np.diff(xlim) == np.diff(ylim))
38383842
assert_true(ax.get_aspect() == 'equal')
38393843

3844+
38403845
@cleanup
38413846
def test_no_None():
38423847
fig, ax = plt.subplots()
@@ -3855,6 +3860,24 @@ def test_pcolor_fast_non_uniform():
38553860
ax.pcolorfast(X, Y, Z.T)
38563861

38573862

3863+
@cleanup
3864+
def test_shared_scale():
3865+
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)
3866+
3867+
axs[0, 0].set_xscale("log")
3868+
axs[0, 0].set_yscale("log")
3869+
3870+
for ax in axs.flat:
3871+
assert_equal(ax.get_yscale(), 'log')
3872+
assert_equal(ax.get_xscale(), 'log')
3873+
3874+
axs[1, 1].set_xscale("linear")
3875+
axs[1, 1].set_yscale("linear")
3876+
3877+
for ax in axs.flat:
3878+
assert_equal(ax.get_yscale(), 'linear')
3879+
assert_equal(ax.get_xscale(), 'linear')
3880+
38583881
if __name__ == '__main__':
38593882
import nose
38603883
import sys

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.