Skip to content

Commit

Permalink
Merge pull request #3612 from nhmc/minor_tick_fix
Browse files Browse the repository at this point in the history
BUG : fix minor tick placement

Merging by hand as I added a testing clean up commit on top of
the original branch.
  • Loading branch information
tacaswell committed Dec 31, 2014
1 parent e475489 commit 50625de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from numpy.testing import assert_almost_equal
import numpy as np
import matplotlib

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker

from matplotlib.testing.decorators import cleanup

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


@cleanup
def test_AutoMinorLocator():
fig, ax = plt.subplots()
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

0 comments on commit 50625de

Please sign in to comment.