8000 Backport PR #28292 on branch v3.9.x (Resolve MaxNLocator IndexError when no large steps) by meeseeksmachine · Pull Request #28327 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Backport PR #28292 on branch v3.9.x (Resolve MaxNLocator IndexError when no large steps) #28327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
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
Loading
0