From bdb53a1d38900f9a1f2b8f0abd9f11978d3f2a79 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Sun, 1 Jan 2012 16:27:03 -1000 Subject: [PATCH] ticker: bugfix for commit #d02676283f; special case for 1 tick --- lib/matplotlib/ticker.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 3e59e5ad2bb2..6fde692db03b 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -455,7 +455,7 @@ def set_locs(self, locs): if self._useOffset: self._set_offset(d) self._set_orderOfMagnitude(d) - self._set_format() + self._set_format(vmin, vmax) def _set_offset(self, range): # offset of 20,001 is 20,000, for example @@ -496,10 +496,19 @@ def _set_orderOfMagnitude(self,range): else: self.orderOfMagnitude = 0 - def _set_format(self): + def _set_format(self, vmin, vmax): # set the format string to format all the ticklabels - locs = (np.asarray(self.locs)-self.offset) / 10**self.orderOfMagnitude - loc_range_oom = int(math.floor(math.log10(np.ptp(locs)))) + if len(self.locs) < 2: + # Temporarily augment the locations with the axis end points. + _locs = list(self.locs) + [vmin, vmax] + else: + _locs = self.locs + locs = (np.asarray(_locs)-self.offset) / 10**self.orderOfMagnitude + loc_range = np.ptp(locs) + if len(self.locs) < 2: + # We needed the end points only for the loc_range calculation. + locs = locs[:-2] + loc_range_oom = int(math.floor(math.log10(loc_range))) # first estimate: sigfigs = max(0, 3 - loc_range_oom) # refined estimate: