Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 229d116

Browse files
aalmasmarioscargus
authored and
alialmas
committed
Update lib/matplotlib/ticker.py
Co-authored-by: Oscar Gustafsson <[email protected]>
1 parent 3f16132 commit 229d116

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ def test_basic(self):
106106
(1, 0) # a single major tick => no minor tick
107107
]
108108

109+
def test_first_and_last_minorticks(self):
110+
"""
111+
Test that first and last minor tick appear as expected.
112+
"""
113+
# This test is related to issue #22331
114+
fig = plt.figure()
115+
ax = plt.gca()
116+
ax.set_xlim(-1.9, 1.9)
117+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
118+
test_value = np.array([-1.9, -1.8, -1.7, -1.6, -1.4, -1.3, -1.2, -1.1,
119+
-0.9, -0.8, -0.7, -0.6, -0.4, -0.3, -0.2, -0.1,
120+
0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9, 1.1,
121+
1.2, 1.3, 1.4, 1.6, 1.7, 1.8, 1.9])
122+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
123+
124+
ax.set_xlim(-5, 5)
125+
test_value = np.array([-5.0, -4.5, -3.5, -3.0, -2.5, -1.5, -1.0, -0.5,
126+
0.5, 1.0, 1.5, 2.5, 3.0, 3.5, 4.5, 5.0])
127+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
128+
109129
@pytest.mark.parametrize('nb_majorticks, expected_nb_minorticks', params)
110130
def test_low_number_of_majorticks(
111131
self, nb_majorticks, expected_nb_minorticks):

lib/matplotlib/ticker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,10 +2953,9 @@ def __call__(self):
29532953
vmin, vmax = vmax, vmin
29542954

29552955
t0 = majorlocs[0]
2956-
tmin = round((vmin - t0) / minorstep) - 1
2956+
tmin = round((vmin - t0) / minorstep)
29572957
tmax = round((vmax - t0) / minorstep) + 1
2958-
locs = np.arange((tmin + 1) * minorstep,
2959-
tmax * minorstep, minorstep) + t0
2958+
locs = (np.arange(tmin, tmax) * minorstep) + t0
29602959

29612960
return self.raise_if_exceeds(locs)
29622961

0 commit comments

Comments
 (0)