diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 5cbba5b88d15..261b8e920f64 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1004,11 +1004,10 @@ def set_inverted(self, inverted): the top for the y-axis; the "inverse" direction is increasing to the left for the x-axis and to the bottom for the y-axis. """ - a, b = self.get_view_interval() - if inverted: - self.set_view_interval(max(a, b), min(a, b), ignore=True) - else: - self.set_view_interval(min(a, b), max(a, b), ignore=True) + # Currently, must be implemented in subclasses using set_xlim/set_ylim + # rather than generically using set_view_interval, so that shared + # axes get updated as well. + raise NotImplementedError('Derived must override') def set_default_intervals(self): """ @@ -2156,6 +2155,11 @@ def get_ticks_position(self): def get_minpos(self): return self.axes.dataLim.minposx + def set_inverted(self, inverted): + # docstring inherited + a, b = self.get_view_interval() + self.axes.set_xlim(sorted((a, b), reverse=inverted), auto=None) + def set_default_intervals(self): # docstring inherited xmin, xmax = 0., 1. @@ -2458,6 +2462,11 @@ def get_ticks_position(self): def get_minpos(self): return self.axes.dataLim.minposy + def set_inverted(self, inverted): + # docstring inherited + a, b = self.get_view_interval() + self.axes.set_ylim(sorted((a, b), reverse=inverted), auto=None) + def set_default_intervals(self): # docstring inherited ymin, ymax = 0., 1. diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 06ff5aca442f..6b48ed02cd00 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -244,17 +244,19 @@ def test_inverted_cla(): ax.cla() ax.imshow(img) plt.autoscale() - assert not(ax.xaxis_inverted()) + assert not ax.xaxis_inverted() assert ax.yaxis_inverted() - # 5. two shared axes. Clearing the master axis should bring axes in shared - # axes back to normal + # 5. two shared axes. Inverting the master axis should invert the shared + # axes; clearing the master axis should bring axes in shared + # axes back to normal. ax0 = plt.subplot(211) ax1 = plt.subplot(212, sharey=ax0) - ax0.imshow(img) + ax0.yaxis.set_inverted(True) + assert ax1.yaxis_inverted() ax1.plot(x, np.cos(x)) ax0.cla() - assert not(ax1.yaxis_inverted()) + assert not ax1.yaxis_inverted() ax1.cla() # 6. clearing the nonmaster should not touch limits ax0.imshow(img)