Closed
Description
This is a relatively minor bug in the way DayLocator tries to report an error message when running the tick_values() method. It is unable to report the invalid input because the invalid input causes a type error while formatting the error message. To be clear, the issue is not that the class breaks with invlaid input but how it breaks with invalid input.
The method could check for Nan or Inf numpy.float64 values before trying to use the %d format, switch to the %f format or catch zero-width intervals at initialization time.
Matplotlib 1.5.2, Anaconda Python 2.7 on Mac OSX
import datetime
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, DayLocator
vals = range(22)
dates = [datetime.datetime(2016, 8, 1, x, 20, 20) for x in range(22)]
plt.plot(dates, vals)
ax = plt.subplot(111)
ax.xaxis.set_major_locator(DayLocator(interval=0)) #causes exception
/Users/cjc73/anaconda/lib/python2.7/site-packages/matplotlib/axis.pyc in iter_ticks(self)
892 Iterate through all of the major and minor ticks.
893 """
--> 894 majorLocs = self.major.locator()
895 majorTicks = self.get_major_ticks(len(majorLocs))
896 self.major.formatter.set_locs(majorLocs)
/Users/cjc73/anaconda/lib/python2.7/site-packages/matplotlib/dates.pyc in __call__(self)
812 return []
813
--> 814 return self.tick_values(dmin, dmax)
815
816 def tick_values(self, vmin, vmax):
/Users/cjc73/anaconda/lib/python2.7/site-packages/matplotlib/dates.pyc in tick_values(self, vmin, vmax)
842 'RRuleLocator estimated to generate %d ticks from %s to %s: '
843 'exceeds Locator.MAXTICKS * 2 (%d) ' % (estimate, vmin, vmax,
--> 844 self.MAXTICKS * 2))
845
846 dates = self.rule.between(vmin, vmax, True)
TypeError: %d format: a number is required, not numpy.float64