Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ab5567

Browse filesBrowse files
authored
Merge pull request #28292 from ddeibert-nso/no_large_steps
Resolve MaxNLocator IndexError when no large steps
2 parents 81627e9 + 5981aa4 commit 0ab5567
Copy full SHA for 0ab5567

File tree

Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-1
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def test_view_limits_round_numbers_with_offset(self):
130130
loc = mticker.MultipleLocator(base=3.147, offset=1.3)
131131
assert_almost_equal(loc.view_limits(-4, 4), (-4.994, 4.447))
132132

133+
def test_view_limits_single_bin(self):
134+
"""
135+
Test that 'round_numbers' works properly with a single bin.
136+
"""
137+
with mpl.rc_context({'axes.autolimit_mode': 'round_numbers'}):
138+
loc = mticker.MaxNLocator(nbins=1)
139+
assert_almost_equal(loc.view_limits(-2.3, 2.3), (-4, 4))
140+
133141
def test_set_params(self):
134142
"""
135143
Create multiple locator with 0.7 base, and change it to something else.

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,10 @@ def _raw_ticks(self, vmin, vmax):
21372137
large_steps = large_steps & (floored_vmaxs >= _vmax)
21382138

21392139
# Find index of smallest large step
2140-
istep = np.nonzero(large_steps)[0][0]
2140+
if any(large_steps):
2141+
istep = np.nonzero(large_steps)[0][0]
2142+
else:
2143+
istep = len(steps) - 1
21412144

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.