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 d49a8df

Browse filesBrowse files
authored
Merge pull request matplotlib#14619 from meeseeksmachine/auto-backport-of-pr-14598-on-v3.1.x
Backport PR matplotlib#14598 on branch v3.1.x (Fix inversion of shared axes.)
2 parents d65c9ca + fc51b41 commit d49a8df
Copy full SHA for d49a8df

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+21
-10
lines changed

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+14-5Lines 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
"""
@@ -2154,6 +2153,11 @@ def get_ticks_position(self):
21542153
def get_minpos(self):
21552154
return self.axes.dataLim.minposx
21562155

2156+
def set_inverted(self, inverted):
2157+
# docstring inherited
2158+
a, b = self.get_view_interval()
2159+
self.axes.set_xlim(sorted((a, b), reverse=inverted), auto=None)
2160+
21572161
def set_default_intervals(self):
21582162
# docstring inherited
21592163
xmin, xmax = 0., 1.
@@ -2456,6 +2460,11 @@ def get_ticks_position(self):
24562460
def get_minpos(self):
24572461
return self.axes.dataLim.minposy
24582462

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

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+7-5Lines 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-
# 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.