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

Skip to content

Commit e9b90c7

Browse files
committed
Merge pull request matplotlib#3612 from nhmc/minor_tick_fix
BUG : fix minor tick placement Merging by hand as I added a testing clean up commit on top of the original branch.
2 parents 478b181 + c991da1 commit e9b90c7

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from numpy.testing import assert_almost_equal
88
import numpy as np
99
import matplotlib
10-
10+
import matplotlib.pyplot as plt
1111
import matplotlib.ticker as mticker
12-
12+
from matplotlib.testing.decorators import cleanup
1313

1414
def test_MaxNLocator():
1515
loc = mticker.MaxNLocator(nbins=5)
@@ -36,6 +36,17 @@ def test_MultipleLocator():
3636
assert_almost_equal(loc.tick_values(-7, 10), test_value)
3737

3838

39+
@cleanup
40+
def test_AutoMinorLocator():
41+
fig, ax = plt.subplots()
42+
ax.set_xlim(0, 1.39)
43+
ax.minorticks_on()
44+
test_value = np.array([0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
45+
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
46+
0.95, 1, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
47+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
48+
49+
3950
def test_LogLocator():
4051
loc = mticker.LogLocator(numticks=5)
4152

lib/matplotlib/ticker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,8 +1747,8 @@ def __call__(self):
17471747

17481748
if len(majorlocs) > 0:
17491749
t0 = majorlocs[0]
1750-
tmin = np.ceil((vmin - t0) / minorstep) * minorstep
1751-
tmax = np.floor((vmax - t0) / minorstep) * minorstep
1750+
tmin = ((vmin - t0) // minorstep + 1) * minorstep
1751+
tmax = ((vmax - t0) // minorstep + 1) * minorstep
17521752
locs = np.arange(tmin, tmax, minorstep) + t0
17531753
cond = np.abs((locs - t0) % majorstep) > minorstep / 10.0
17541754
locs = locs.compress(cond)

0 commit comments

Comments
 (0)