Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2673,10 +2673,14 @@ def set_xscale(self, value, **kwargs):
# around zero
if value.lower() == 'log' and 'nonposx' not in kwargs.keys():
kwargs['nonposx'] = 'clip'
self.xaxis._set_scale(value, **kwargs)

g = self.get_shared_x_axes()
for ax in g.get_siblings(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does get_siblings() return itself along with siblings? If not, then doesn't the self axes miss out on updating?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does return it's self

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, do we have to watch out for possible infinite recursion?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, because this is reaching in and touching the inner bits of all of the axes axis, not coming through the ax.set_xscale method (which is where we would get recursion). My first attempt did use recursion, but I think this is simpler as we don't need the logic to prevent the infinite recursion.

ax.xaxis._set_scale(value, **kwargs)
ax._update_transScale()
ax.stale = True

self.autoscale_view(scaley=False)
self._update_transScale()
self.stale = True

def get_xticks(self, minor=False):
"""Return the x ticks as a list of locations"""
Expand Down Expand Up @@ -2926,10 +2930,13 @@ def set_yscale(self, value, **kwargs):
# around zero
if value.lower() == 'log' and 'nonposy' not in kwargs.keys():
kwargs['nonposy'] = 'clip'
self.yaxis._set_scale(value, **kwargs)

g = self.get_shared_y_axes()
for ax in g.get_siblings(self):
ax.yaxis._set_scale(value, **kwargs)
ax._update_transScale()
ax.stale = True
self.autoscale_view(scalex=False)
self._update_transScale()
self.stale = True

def get_yticks(self, minor=False):
"""Return the y ticks as a list of locations"""
Expand Down
27 changes: 25 additions & 2 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3796,8 +3796,9 @@ def test_rc_spines():
with matplotlib.rc_context(rc_dict):
fig, ax = plt.subplots()


@image_comparison(baseline_images=['rc_grid'], extensions=['png'],
savefig_kwarg={'dpi':40})
savefig_kwarg={'dpi': 40})
def test_rc_grid():
fig = plt.figure()
rc_dict0 = {
Expand All @@ -3811,11 +3812,13 @@ def test_rc_grid():
}
dict_list = [rc_dict0, rc_dict1, rc_dict2]

i=1
i = 1
for rc_dict in dict_list:
with matplotlib.rc_context(rc_dict):
fig.add_subplot(3, 1, i)
i += 1


@cleanup
def test_bar_negative_width():
fig, ax = plt.subplots()
Expand All @@ -3826,6 +3829,7 @@ def test_bar_negative_width():
assert_equal(b._width, 1)
assert_equal(b._height, indx + 1)


@cleanup
def test_square_plot():
x = np.arange(4)
Expand All @@ -3837,6 +3841,7 @@ def test_square_plot():
assert_true(np.diff(xlim) == np.diff(ylim))
assert_true(ax.get_aspect() == 'equal')


@cleanup
def test_no_None():
fig, ax = plt.subplots()
Expand All @@ -3855,6 +3860,24 @@ def test_pcolor_fast_non_uniform():
ax.pcolorfast(X, Y, Z.T)


@cleanup
def test_shared_scale():
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True)

axs[0, 0].set_xscale("log")
axs[0, 0].set_yscale("log")

for ax in axs.flat:
assert_equal(ax.get_yscale(), 'log')
assert_equal(ax.get_xscale(), 'log')

axs[1, 1].set_xscale("linear")
axs[1, 1].set_yscale("linear")

for ax in axs.flat:
assert_equal(ax.get_yscale(), 'linear')
assert_equal(ax.get_xscale(), 'linear')

if __name__ == '__main__':
import nose
import sys
Expand Down