Skip to content

Commit 1d1b48b

Browse files
authored
Merge pull request #25970 from neutrinoceros/inclusive_symlog_regions
FIX: resolve an issue where no ticks would be drawn for a colorbar with SymLogNorm and ranging exactly from 0 to linthresh
2 parents 3218d1f + a3306b2 commit 1d1b48b

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/matplotlib/tests/test_ticker.py

+13
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,19 @@ def test_set_params(self):
560560
assert sym._subs == [2.0]
561561
assert sym.numticks == 8
562562

563+
@pytest.mark.parametrize(
564+
'vmin, vmax, expected',
565+
[
566+
(0, 1, [0, 1]),
567+
(-1, 1, [-1, 0, 1]),
568+
],
569+
)
570+
def test_values(self, vmin, vmax, expected):
571+
# https://github.com/matplotlib/matplotlib/issues/25945
572+
sym = mticker.SymmetricalLogLocator(base=10, linthresh=1)
573+
ticks = sym.tick_values(vmin=vmin, vmax=vmax)
574+
assert_array_equal(ticks, expected)
575+
563576

564577
class TestAsinhLocator:
565578
def test_init(self):

lib/matplotlib/ticker.py

+4-4
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})
25042504

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

0 commit comments

Comments
 (0)