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

Commit177164d

Browse files
committed
Fix axis inversion with loglocator and logitlocator.
1 parent5c413df commit177164d

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

‎doc/api/next_api_changes/2019-03-04-AL.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@ without an explicit call to `Axes.autoscale_view`.
1212

1313
In some cases, this can result in different limits being reported. If this is
1414
an issue, consider triggering a draw with `fig.canvas.draw`.
15-
16-
LogLocator.nonsingular now maintains the orders of its arguments
17-
````````````````````````````````````````````````````````````````
18-
19-
It no longer reorders them in increasing order. The new behavior is consistent
20-
with MaxNLocator.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
API changes
2+
```````````
3+
4+
`Locator.nonsingular` (introduced in mpl 3.1), `DateLocator.nonsingular`, and
5+
`AutoDateLocator.nonsingular` now returns a range ``v0, v1`` with ``v0 <= v1``.
6+
This behavior is consistent with the implementation of ``nonsingular`` by the
7+
`LogLocator` and `LogitLocator` subclasses.

‎lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,8 +3266,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
32663266
cbook._warn_external(
32673267
f"Attempting to set identical left == right =={left} results "
32683268
f"in singular transformations; automatically expanding.")
3269+
swapped=left>right
32693270
left,right=self.xaxis.get_major_locator().nonsingular(left,right)
32703271
left,right=self.xaxis.limit_range_for_scale(left,right)
3272+
ifswapped:
3273+
left,right=right,left
32713274

32723275
self._viewLim.intervalx= (left,right)
32733276
ifautoisnotNone:
@@ -3647,8 +3650,11 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36473650
f"Attempting to set identical bottom == top =={bottom} "
36483651
f"results in singular transformations; automatically "
36493652
f"expanding.")
3653+
swapped=bottom>top
36503654
bottom,top=self.yaxis.get_major_locator().nonsingular(bottom,top)
36513655
bottom,top=self.yaxis.limit_range_for_scale(bottom,top)
3656+
ifswapped:
3657+
bottom,top=top,bottom
36523658

36533659
self._viewLim.intervaly= (bottom,top)
36543660
ifautoisnotNone:

‎lib/matplotlib/dates.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,8 +1124,9 @@ def nonsingular(self, vmin, vmax):
11241124
"""
11251125
Given the proposed upper and lower extent, adjust the range
11261126
if it is too close to being singular (i.e. a range of ~0).
1127-
11281127
"""
1128+
ifvmax<vmin:
1129+
vmin,vmax=vmax,vmin
11291130
unit=self._get_unit()
11301131
interval=self._get_interval()
11311132
ifabs(vmax-vmin)<1e-6:
@@ -1342,6 +1343,8 @@ def tick_values(self, vmin, vmax):
13421343
defnonsingular(self,vmin,vmax):
13431344
# whatever is thrown at us, we can scale the unit.
13441345
# But default nonsingular date plots at an ~4 year period.
1346+
ifvmax<vmin:
1347+
vmin,vmax=vmax,vmin
13451348
ifvmin==vmax:
13461349
vmin=vmin-DAYS_PER_YEAR*2
13471350
vmax=vmax+DAYS_PER_YEAR*2

‎lib/matplotlib/tests/test_axes.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,12 @@ def test_inverted_limits():
899899

900900
assertax.get_xlim()== (-5,4)
901901
assertax.get_ylim()== (5,-3)
902-
plt.close()
902+
903+
# Test inverting nonlinear axes.
904+
fig,ax=plt.subplots()
905+
ax.set_yscale("log")
906+
ax.set_ylim(10,1)
907+
assertax.get_ylim()== (10,1)
903908

904909

905910
@image_comparison(['nonfinite_limits'])

‎lib/matplotlib/ticker.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,8 +1520,8 @@ def raise_if_exceeds(self, locs):
15201520
returnlocs
15211521

15221522
defnonsingular(self,v0,v1):
1523-
"""Modify the endpoints of a range as needed to avoid singularities."""
1524-
returnmtransforms.nonsingular(v0,v1,increasing=False,expander=.05)
1523+
"""Expand a range as needed to avoid singularities."""
1524+
returnmtransforms.nonsingular(v0,v1,expander=.05)
15251525

15261526
defview_limits(self,vmin,vmax):
15271527
"""
@@ -2317,9 +2317,7 @@ def view_limits(self, vmin, vmax):
23172317
returnvmin,vmax
23182318

23192319
defnonsingular(self,vmin,vmax):
2320-
swap_vlims=False
23212320
ifvmin>vmax:
2322-
swap_vlims=True
23232321
vmin,vmax=vmax,vmin
23242322
ifnotnp.isfinite(vmin)ornotnp.isfinite(vmax):
23252323
vmin,vmax=1,10# Initial range, no data plotted yet.
@@ -2337,8 +2335,6 @@ def nonsingular(self, vmin, vmax):
23372335
ifvmin==vmax:
23382336
vmin=_decade_less(vmin,self._base)
23392337
vmax=_decade_greater(vmax,self._base)
2340-
ifswap_vlims:
2341-
vmin,vmax=vmax,vmin
23422338
returnvmin,vmax
23432339

23442340

‎lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,11 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
632632
cbook._warn_external(
633633
f"Attempting to set identical left == right =={left} results "
634634
f"in singular transformations; automatically expanding.")
635+
swapped=left>right
635636
left,right=self.xaxis.get_major_locator().nonsingular(left,right)
636637
left,right=self.xaxis.limit_range_for_scale(left,right)
638+
ifswapped:
639+
left,right=right,left
637640
self.xy_viewLim.intervalx= (left,right)
638641

639642
ifautoisnotNone:
@@ -690,8 +693,11 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
690693
f"Attempting to set identical bottom == top =={bottom} "
691694
f"results in singular transformations; automatically "
692695
f"expanding.")
696+
swapped=bottom>top
693697
bottom,top=self.yaxis.get_major_locator().nonsingular(bottom,top)
694698
bottom,top=self.yaxis.limit_range_for_scale(bottom,top)
699+
ifswapped:
700+
bottom,top=top,bottom
695701
self.xy_viewLim.intervaly= (bottom,top)
696702

697703
ifautoisnotNone:
@@ -748,8 +754,11 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
748754
f"Attempting to set identical bottom == top =={bottom} "
749755
f"results in singular transformations; automatically "
750756
f"expanding.")
757+
swapped=bottom>top
751758
bottom,top=self.zaxis.get_major_locator().nonsingular(bottom,top)
752759
bottom,top=self.zaxis.limit_range_for_scale(bottom,top)
760+
ifswapped:
761+
bottom,top=top,bottom
753762
self.zz_viewLim.intervalx= (bottom,top)
754763

755764
ifautoisnotNone:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp