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

Skip to content

Commit bdb53a1

Browse files
committed
ticker: bugfix for commit #d02676283f; special case for 1 tick
1 parent c14c483 commit bdb53a1

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/matplotlib/ticker.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def set_locs(self, locs):
455455
if self._useOffset:
456456
self._set_offset(d)
457457
self._set_orderOfMagnitude(d)
458-
self._set_format()
458+
self._set_format(vmin, vmax)
459459

460460
def _set_offset(self, range):
461461
# offset of 20,001 is 20,000, for example
@@ -496,10 +496,19 @@ def _set_orderOfMagnitude(self,range):
496496
else:
497497
self.orderOfMagnitude = 0
498498

499-
def _set_format(self):
499+
def _set_format(self, vmin, vmax):
500500
# set the format string to format all the ticklabels
501-
locs = (np.asarray(self.locs)-self.offset) / 10**self.orderOfMagnitude
502-
loc_range_oom = int(math.floor(math.log10(np.ptp(locs))))
501+
if len(self.locs) < 2:
502+
# Temporarily augment the locations with the axis end points.
503+
_locs = list(self.locs) + [vmin, vmax]
504+
else:
505+
_locs = self.locs
506+
locs = (np.asarray(_locs)-self.offset) / 10**self.orderOfMagnitude
507+
loc_range = np.ptp(locs)
508+
if len(self.locs) < 2:
509+
# We needed the end points only for the loc_range calculation.
510+
locs = locs[:-2]
511+
loc_range_oom = int(math.floor(math.log10(loc_range)))
503512
# first estimate:
504513
sigfigs = max(0, 3 - loc_range_oom)
505514
# refined estimate:

0 commit comments

Comments
 (0)