Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit5c413df

Browse files
authored
Merge pull request#14598 from anntzer/invertshared
FIX: inversion of shared axes.
2 parents3bacb5f +0e95296 commit5c413df

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
@@ -1028,11 +1028,10 @@ def set_inverted(self, inverted):
10281028
the top for the y-axis; the "inverse" direction is increasing to the
10291029
left for the x-axis and to the bottom for the y-axis.
10301030
"""
1031-
a,b=self.get_view_interval()
1032-
ifinverted:
1033-
self.set_view_interval(max(a,b),min(a,b),ignore=True)
1034-
else:
1035-
self.set_view_interval(min(a,b),max(a,b),ignore=True)
1031+
# Currently, must be implemented in subclasses using set_xlim/set_ylim
1032+
# rather than generically using set_view_interval, so that shared
1033+
# axes get updated as well.
1034+
raiseNotImplementedError('Derived must override')
10361035

10371036
defset_default_intervals(self):
10381037
"""
@@ -2171,6 +2170,11 @@ def get_ticks_position(self):
21712170
defget_minpos(self):
21722171
returnself.axes.dataLim.minposx
21732172

2173+
defset_inverted(self,inverted):
2174+
# docstring inherited
2175+
a,b=self.get_view_interval()
2176+
self.axes.set_xlim(sorted((a,b),reverse=inverted),auto=None)
2177+
21742178
defset_default_intervals(self):
21752179
# docstring inherited
21762180
xmin,xmax=0.,1.
@@ -2473,6 +2477,11 @@ def get_ticks_position(self):
24732477
defget_minpos(self):
24742478
returnself.axes.dataLim.minposy
24752479

2480+
defset_inverted(self,inverted):
2481+
# docstring inherited
2482+
a,b=self.get_view_interval()
2483+
self.axes.set_ylim(sorted((a,b),reverse=inverted),auto=None)
2484+
24762485
defset_default_intervals(self):
24772486
# docstring inherited
24782487
ymin,ymax=0.,1.

‎lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,19 @@ def test_inverted_cla():
240240
ax.cla()
241241
ax.imshow(img)
242242
plt.autoscale()
243-
assertnot(ax.xaxis_inverted())
243+
assertnotax.xaxis_inverted()
244244
assertax.yaxis_inverted()
245245

246-
# 5. two shared axes. Clearing the master axis should bring axes in shared
247-
# axes back to normal
246+
# 5. two shared axes. Inverting the master axis should invert the shared
247+
# axes; clearing the master axis should bring axes in shared
248+
# axes back to normal.
248249
ax0=plt.subplot(211)
249250
ax1=plt.subplot(212,sharey=ax0)
250-
ax0.imshow(img)
251+
ax0.yaxis.set_inverted(True)
252+
assertax1.yaxis_inverted()
251253
ax1.plot(x,np.cos(x))
252254
ax0.cla()
253-
assertnot(ax1.yaxis_inverted())
255+
assertnotax1.yaxis_inverted()
254256
ax1.cla()
255257
# 6. clearing the nonmaster should not touch limits
256258
ax0.imshow(img)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp