8000 add test for AutoMinorLocator with low number of major ticks · matplotlib/matplotlib@3418d96 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3418d96

Browse files
committed
add test for AutoMinorLocator with low number of major ticks
1 parent 1abd72d commit 3418d96

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ 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+
# NB: the following values are assuming that *xlim* is [0, 5]
84+
params = [
85+
(0, 0), # no major tick => no minor tick either
86+
(1, 0), # a single major tick => no minor tick
87+
(2, 4), # 1 "nice" major step => 1*5 minor **divisions**
88+
(3, 6) # 2 "not nice" major steps => 2*4 minor **divisions**
89+
]
90+
91+
@pytest.mark.parametrize('nb_majorticks, expected_nb_minorticks', params)
92+
def test_low_number_of_majorticks(
93+
self, nb_majorticks, expected_nb_minorticks):
94+
# This test is related to issue #8804
95+
fig, ax = plt.subplots()
96+
xlims = (0, 5) # easier to test the different code paths
97+
ax.set_xlim(*xlims)
98+
ax.set_xticks(np.linspace(xlims[0], xlims[1], nb_majorticks))
99+
ax.minorticks_on()
100+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
101+
assert len(ax.xaxis.get_minorticklocs()) == expected_nb_minorticks
102+
83103

84104
class TestLogLocator(object):
85105
def test_basic(self):

0 commit comments

Comments
 (0)
0