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 f51fa53

Browse filesBrowse files
committed
avoid the case that divides by zero (+ test)
1 parent 6657fe1 commit f51fa53
Copy full SHA for f51fa53

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+10
-1
lines changed

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ def test_basic(self):
8080
0.95, 1, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
8181
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
8282

83+
def test_single_majorloc(self):
84+
# related to issue 8804
85+
fig, ax = plt.subplots()
86+
ax.set_xlim(-0.9, 0.9)
87+
ax.set_xticks([0]) # force a single major tick position
88+
ax.minorticks_on()
89+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
90+
assert len(ax.xaxis.get_minorticklocs()) == 0
91+
8392

8493
class TestLogLocator(object):
8594
def test_basic(self):

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,7 @@ def __call__(self):
25452545
if vmin > vmax:
25462546
vmin, vmax = vmax, vmin
25472547

2548-
if len(majorlocs) > 0:
2548+
if len(majorlocs) >= 2:
25492549
t0 = majorlocs[0]
25502550
tmin = ((vmin - t0) // minorstep + 1) * minorstep
25512551
tmax = ((vmax - t0) // minorstep + 1) * minorstep

0 commit comments

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