00__00__00
00__00__00

Reputation: 5347

mdates.DateLocator() raising NotImplemented error

I am still working on getting nice rounded datatime in xticks: rounding datetimes in xticks matplotlib

So the answer was fine, and I could use

plt.gca().xaxis.set_major_locator(mdates.HourLocator()) 

to get round hours in the xticks.

However, if I simply do

plt.gca().xaxis.set_major_locator(mdates.DateLocator()) 

it gives:

  File "/python/anaconda-2.7.11-64/lib/python2.7/site-packages    /matplotlib/ticker.py", line 1289, in __call__
    raise NotImplementedError('Derived must override')
NotImplementedError: Derived must override

Is it really impossible to change HourLocator() to DateLocator() ? I am using matplotlib.__version__'2.0.2'

Upvotes: 0

Views: 1796

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339560

You are not meant do use DateLocator by itself. This is the baseclass of all other locators for dates that matplotlib provides. The matplotlib dates API page lists the possible locators to be

Here are all the date tickers:

  • MinuteLocator: locate minutes
  • HourLocator: locate hours
  • DayLocator: locate specifed days of the month
  • WeekdayLocator: Locate days of the week, e.g., MO, TU
  • MonthLocator: locate months, e.g., 7 for july
  • YearLocator: locate years that are multiples of base
  • RRuleLocator: locate using a matplotlib.dates.rrulewrapper. The rrulewrapper is a simple wrapper around a dateutil.rrule (dateutil) which allow almost arbitrary date tick specifications. See rrule example.
  • AutoDateLocator: On autoscale, this class picks the best MultipleDateLocator to set the view limits and the tick locations.

Choose any one of those and you will be fine.

In addition to those mentionned, there is also a SecondLocator and a MicrosecondLocator available, which are not (well) documented.

Upvotes: 3

Related Questions