Skip to content

Commit

Permalink
ticker: bugfix for commit #d02676283f; special case for 1 tick
Browse files Browse the repository at this point in the history
  • Loading branch information
efiring committed Jan 2, 2012
1 parent c14c483 commit bdb53a1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/matplotlib/ticker.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit bdb53a1

Please sign in to comment.