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

Commitf8b814e

Browse files
authored
Merge pull request#18754 from tacaswell/fix_log_ticks
FIX: make sure we have more than 1 tick with small log ranges
2 parentsd872350 +b23a874 commitf8b814e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎lib/matplotlib/tests/test_ticker.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,3 +1362,13 @@ def test_bad_locator_subs(sub):
13621362
ll=mticker.LogLocator()
13631363
withpytest.raises(ValueError):
13641364
ll.subs(sub)
1365+
1366+
1367+
@pytest.mark.parametrize('numticks', [1,2,3,9])
1368+
@pytest.mark.style('default')
1369+
deftest_small_range_loglocator(numticks):
1370+
ll=mticker.LogLocator()
1371+
ll.set_params(numticks=numticks)
1372+
fortopin [5,7,9,11,15,50,100,1000]:
1373+
ticks=ll.tick_values(.5,top)
1374+
assert (np.diff(np.log10(ll.tick_values(6,150)))==1).all()

‎lib/matplotlib/ticker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,13 @@ def tick_values(self, vmin, vmax):
24792479
ifmpl.rcParams['_internal.classic_mode']else
24802480
(numdec+1)//numticks+1)
24812481

2482+
# if we have decided that the stride is as big or bigger than
2483+
# the range, clip the stride back to the available range - 1
2484+
# with a floor of 1. This prevents getting axis with only 1 tick
2485+
# visible.
2486+
ifstride>=numdec:
2487+
stride=max(1,numdec-1)
2488+
24822489
# Does subs include anything other than 1? Essentially a hack to know
24832490
# whether we're a major or a minor locator.
24842491
have_subs=len(subs)>1or (len(subs)==1andsubs[0]!=1.0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp