Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def test_MultipleLocator():
assert_almost_equal(loc.tick_values(-7, 10), test_value)


def test_AutoMinorLocator():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that this test is creating a figure which is leaking out and getting re-used in the next test (global state strikes again!).

This test either needs an @cleanup decorator or to be re-written to test the locator without creating a figure/axes. I strongly prefer the second.

from pylab import figure
fig = figure()
ax = fig.add_subplot(111)
ax.set_xlim(0, 1.39)
ax.minorticks_on()
test_value = np.array([0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
0.95, 1, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)


def test_LogLocator():
loc = mticker.LogLocator(numticks=5)

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,8 @@ def __call__(self):

if len(majorlocs) > 0:
t0 = majorlocs[0]
tmin = np.ceil((vmin - t0) / minorstep) * minorstep
tmax = np.floor((vmax - t0) / minorstep) * minorstep
tmin = ((vmin - t0) // minorstep + 1) * minorstep
tmax = ((vmax - t0) // minorstep + 1) * minorstep
locs = np.arange(tmin, tmax, minorstep) + t0
cond = np.abs((locs - t0) % majorstep) > minorstep / 10.0
locs = locs.compress(cond)
Expand Down