Finding good tick values and formatting the ticks for an axis that
has date data is often a challenge. ConciseDateFormatter is
meant to improve the strings chosen for the ticklabels, and to minimize
the strings used in those tick labels as much as possible.
The default date formatter is quite verbose, so we have the option of
using ConciseDateFormatter, as shown below. Note that
for this example the labels do not need to be rotated as they do for the
default formatter because the labels are as small as possible.
If all calls to axes that have dates are to be made using this converter,
it is probably most convenient to use the units registry where you do
imports:
Dates formats can be localized if the default formats are not desirable by
manipulating one of three lists of strings.
The formatter.formats list of formats is for the normal tick labels,
There are six levels: years, months, days, hours, minutes, seconds.
The formatter.offset_formats is how the "offset" string on the right
of the axis is formatted. This is usually much more verbose than the tick
labels. Finally, the formatter.zero_formats are the formats of the
ticks that are "zeros". These are tick values that are either the first of
the year, month, or day of month, or the zeroth hour, minute, or second.
These are usually the same as the format of
the ticks a level above. For example if the axis limits mean the ticks are
mostly days, then we label 1 Mar 2005 simply with a "Mar". If the axis
limits are mostly hours, we label Feb 4 00:00 as simply "Feb-4".
Note that these format lists can also be passed to ConciseDateFormatter
as optional keyword arguments.
Here we modify the labels to be "day month year", instead of the ISO
"year month day":
ConciseDateFormatter doesn't have rcParams entries, but localization can
be accomplished by passing keyword arguments to ConciseDateConverter and
registering the datatypes you will use with the units registry: