8000 Backport PR #14598: Fix inversion of shared axes. · matplotlib/matplotlib@fc51b41 · GitHub
[go: up one dir, main page]

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 fc51b41

Browse files
tacaswellMeeseeksDev[bot]
authored andcommitted
Backport PR #14598: Fix inversion of shared axes.
1 parent cdf9e30 commit fc51b41

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lib/matplotlib/axis.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,11 +1004,10 @@ def set_inverted(self, inverted):
10041004
the top for the y-axis; the "inverse" direction is increasing to the
10051005
left for the x-axis and to the bottom for the y-axis.
10061006
"""
1007-
a, b = self.get_view_interval()
1008-
if inverted:
1009-
self.set_view_interval(max(a, b), min(a, b), ignore=True)
1010-
else:
1011-
self.set_view_interval(min(a, b), max(a, b), ignore=True)
1007+
# Currently, must be implemented in subclasses using set_xlim/set_ylim
1008+
# rather than generically using set_view_interval, so that shared
1009+
# axes get updated as well.
1010+
raise NotImplementedError('Derived must override')
10121011

10131012
def set_default_intervals(self):
10141013
"""
@@ -2156,6 +2155,11 @@ def get_ticks_position(self):
21562155
def get_minpos(self):
21572156
return self.axes.dataLim.minposx
21582157

2158+
def set_inverted(self, inverted):
2159+
# docstring inherited
2160+
a, b = self.get_view_interval()
2161+
self.axes.set_xlim(sorted((a, b), reverse=inverted), auto=None)
2162+
21592163
def set_default_intervals(self):
21602164
# docstring inherited
21612165
xmin, xmax = 0., 1.
@@ -2458,6 +2462,11 @@ def get_ticks_position(self):
24582462
def get_minpos(self):
24592463
return self.axes.dataLim.minposy
24602464

2465+
def set_inverted(self, inverted):
2466+
# docstring inherited
2467+
a, b = self.get_view_interval()
2468+
self.axes.set_ylim(sorted((a, b), reverse=inverted), auto=None)
2469+
24612470
def set_default_intervals(self):
24622471
# docstring inherited
24632472
ymin, ymax = 0., 1.

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,19 @@ def test_inverted_cla():
244244
ax.cla()
245245
ax.imshow(img)
246246
plt.autoscale()
247-
assert not(ax.xaxis_inverted())
247+
assert not ax.xaxis_inverted()
248248
assert ax.yaxis_inverted()
249249

250 944E -
# 5. two shared axes. Clearing the master axis should bring axes in shared
251-
# axes back to normal
250+
# 5. two shared axes. Inverting the master axis should invert the shared
251+
# axes; clearing the master axis should bring axes in shared
252+
# axes back to normal.
252253
ax0 = plt.subplot(211)
253254
ax1 = plt.subplot(212, sharey=ax0)
254-
ax0.imshow(img)
255+
ax0.yaxis.set_inverted(True)
256+
assert ax1.yaxis_inverted()
255257
ax1.plot(x, np.cos(x))
256258
ax0.cla()
257-
assert not(ax1.yaxis_inverted())
259+
assert not ax1.yaxis_inverted()
258260
ax1.cla()
259261
# 6. clearing the nonmaster should not touch limits
260262
ax0.imshow(img)

0 commit comments

Comments
 (0)
0