8000 FIX: resolve an issue where no ticks would be drawn for a colorbar wi… · matplotlib/matplotlib@a3306b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3306b2

Browse files
neutrinocerosrcomer
andcommitted
FIX: resolve an issue where no ticks would be drawn for a colorbar with SymLogNorm and ranging exactly from 0 to linthresh
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parent 7d7f6da commit a3306b2

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,19 @@ def test_set_params(self):
506506
assert sym._subs == [2.0]
507507
assert sym.numticks == 8
508508

509+
@pytest.mark.parametrize(
510+
'vmin, vmax, expected',
511+
[
512+
(0, 1, [0, 1]),
513+
(-1, 1, [-1, 0, 1]),
514+
],
515+
)
516+
def test_values(self, vmin, vmax, expected):
517+
# https://github.com/matplotlib/matplotlib/issues/25945
518+
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
519+
ticks = sym.tick_values(vmin=vmin, vmax=vmax)
520+
assert_array_equal(ticks, expected)
521+
509522

510523
class TestAsinhLocator:
511524
def test_init(self):

lib/matplotlib/ticker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,11 +2496,11 @@ def tick_values(self, vmin, vmax):
24962496
# We could also add ticks at t, but that seems to usually be
24972497
# uninteresting.
24982498
#
2499-
# "simple" mode is when the range falls entirely within (-t,
2500-
# t) -- it should just display (vmin, 0, vmax)
2501-
if -linthresh < vmin < vmax < linthresh:
2499+
# "simple" mode is when the range falls entirely within [-t, t]
2500+
# -- it should just display (vmin, 0, vmax)
2501+
if -linthresh <= vmin < vmax <= linthresh:
25022502
# only the linear range is present
2503-
return [vmin, vmax]
2503+
return sorted({vmin, 0, vmax})
4581 25042504

25052505
# Lower log range is present
25062506
has_a = (vmin < -linthresh)

0 commit comments

Comments
 (0)
0