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

Skip to content

Issue 807 auto minor locator #961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2012
Merged
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
36 changes: 23 additions & 13 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,15 +1527,22 @@ def __call__(self):
try:
majorstep = majorlocs[1] - majorlocs[0]
except IndexError:
raise ValueError('Need at least two major ticks to find minor '
'tick locations')
# Need at least two major ticks to find minor tick locations
# TODO: Figure out a way to still be able to display minor
# ticks without two major ticks visible. For now, just display
# no ticks at all.
majorstep = 0

if self.ndivs is None:
x = int(round(10 ** (np.log10(majorstep) % 1)))
if x in [1, 5, 10]:
ndivs = 5
else:
ndivs = 4
if majorstep == 0 :
# TODO: Need a better way to figure out ndivs
ndivs = 1
else :
x = int(round(10 ** (np.log10(majorstep) % 1)))
if x in [1, 5, 10]:
ndivs = 5
else:
ndivs = 4
else:
ndivs = self.ndivs

Expand All @@ -1545,12 +1552,15 @@ def __call__(self):
if vmin > vmax:
vmin,vmax = vmax,vmin

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

return self.raise_if_exceeds(np.array(locs))

Expand Down