Skip to content

Commit

Permalink
Merge pull request #28292 from ddeibert-nso/no_large_steps
Browse files Browse the repository at this point in the history
Resolve MaxNLocator IndexError when no large steps
  • Loading branch information
tacaswell committed Jun 2, 2024
2 parents 81627e9 + 5981aa4 commit 0ab5567
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def test_view_limits_round_numbers_with_offset(self):
loc = mticker.MultipleLocator(base=3.147, offset=1.3)
assert_almost_equal(loc.view_limits(-4, 4), (-4.994, 4.447))

def test_view_limits_single_bin(self):
"""
Test that 'round_numbers' works properly with a single bin.
"""
with mpl.rc_context({'axes.autolimit_mode': 'round_numbers'}):
loc = mticker.MaxNLocator(nbins=1)
assert_almost_equal(loc.view_limits(-2.3, 2.3), (-4, 4))

def test_set_params(self):
"""
Create multiple locator with 0.7 base, and change it to something else.
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,10 @@ def _raw_ticks(self, vmin, vmax):
large_steps = large_steps & (floored_vmaxs >= _vmax)

# Find index of smallest large step
istep = np.nonzero(large_steps)[0][0]
if any(large_steps):
istep = np.nonzero(large_steps)[0][0]
else:
istep = len(steps) - 1

# Start at smallest of the steps greater than the raw step, and check
# if it provides enough ticks. If not, work backwards through
Expand Down

0 comments on commit 0ab5567

Please sign in to comment.