Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,22 @@ def test_set_params(self):
assert index._base == 7
assert index.offset == 7

def test_tick_values_not_exceeding_vmax(self):
"""
Test that tick_values does not return values greater than vmax.
"""
# Test case where offset=0 could cause vmax to be included incorrectly
index = mticker.IndexLocator(base=1, offset=0)
assert_array_equal(index.tick_values(0, 4), [0, 1, 2, 3, 4])

# Test case with fractional offset
index = mticker.IndexLocator(base=1, offset=0.5)
assert_array_equal(index.tick_values(0, 4), [0.5, 1.5, 2.5, 3.5])

# Test case with base > 1
index = mticker.IndexLocator(base=2, offset=0)
assert_array_equal(index.tick_values(0, 5), [0, 2, 4])


class TestSymmetricalLogLocator:
def test_set_params(self):
Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,11 @@ def __call__(self):
return self.tick_values(dmin, dmax)

def tick_values(self, vmin, vmax):
return self.raise_if_exceeds(
np.arange(vmin + self.offset, vmax + 1, self._base))
# We want tick values in the closed interval [vmin, vmax].
# Since np.arange(start, stop) returns values in the semi-open interval
# [start, stop), we add a minimal offset so that stop = vmax + eps
tick_values = np.arange(vmin + self.offset, vmax + 1e-12, self._base)
return self.raise_if_exceeds(tick_values)


class FixedLocator(Locator):
Expand Down
Loading