8000 avoid the case that divides by zero (+ test) · matplotlib/matplotlib@f51fa53 · GitHub
[go: up one dir, main page]

Skip to content

Commit f51fa53

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

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines 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

Lines 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