diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index e266b6f60ee8..4a955a667a10 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -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 @@ -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))