matplotlib.dates

Matplotlib provides sophisticated date plotting capabilities, standing on the shoulders of python datetime and the add-on module dateutil.

By default, Matplotlib uses the units machinery described in ~matplotlib.units to convert datetime.datetime, and numpy.datetime64 objects when plotted on an x- or y-axis. The user does not need to do anything for dates to be formatted, but dates often have strict formatting needs, so this module provides many axis locators and formatters. A basic example using numpy.datetime64 is:

import numpy as np

times = np.arange(np.datetime64('2001-01-02'),
                  np.datetime64('2002-02-03'), np.timedelta64(75, 'm'))
y = np.random.randn(len(times))

fig, ax = plt.subplots()
ax.plot(times, y)

See also

  • /gallery/text_labels_and_annotations/date

  • /gallery/ticks/date_concise_formatter

  • /gallery/ticks/date_demo_convert

Matplotlib date format

Matplotlib represents dates using floating point numbers specifying the number of days since a default epoch of 1970-01-01 UTC; for example, 1970-01-01, 06:00 is the floating point number 0.25. The formatters and locators require the use of datetime.datetime objects, so only dates between year 0001 and 9999 can be represented. Microsecond precision is achievable for (approximately) 70 years on either side of the epoch, and 20 microseconds for the rest of the allowable range of dates (year 0001 to 9999). The epoch can be changed at import time via .dates.set_epoch or :rc:`dates.epoch` to other dates if necessary; see /gallery/ticks/date_precision_and_epochs for a discussion.

Note

Before Matplotlib 3.3, the epoch was 0000-12-31 which lost modern microsecond precision and also made the default axis limit of 0 an invalid datetime. In 3.3 the epoch was changed as above. To convert old ordinal floats to the new epoch, users can do:

new_ordinal = old_ordinal + mdates.date2num(np.datetime64('0000-12-31'))

There are a number of helper functions to convert between datetime objects and Matplotlib dates:

Note

Like Python’s datetime.datetime, Matplotlib uses the Gregorian calendar for all conversions between dates and floating point numbers. This practice is not universal, and calendar differences can cause confusing differences between what Python and Matplotlib give as the number of days since 0001-01-01 and what other software and databases yield. For example, the US Naval Observatory uses a calendar that switches from Julian to Gregorian in October, 1582. Hence, using their calculator, the number of days between 0001-01-01 and 2006-04-01 is 732403, whereas using the Gregorian calendar via the datetime module we find:

In [1]: date(2006, 4, 1).toordinal() - date(1, 1, 1).toordinal()
Out[1]: 732401

All the Matplotlib date converters, tickers and formatters are timezone aware. If no explicit timezone is provided, :rc:`timezone` is assumed, provided as a string. If you want to use a different timezone, pass the tz keyword argument of num2date to any date tickers or locators you create. This can be either a datetime.tzinfo instance or a string with the timezone name that can be parsed by ~dateutil.tz.gettz.

A wide range of specific and general purpose date tick locators and formatters are provided in this module. See matplotlib.ticker for general information on tick locators and formatters. These are described below.

The dateutil module provides additional code to handle date ticking, making it easy to place ticks on any kinds of dates. See examples below.

Date tickers

Most of the date tickers can locate single or multiple values. For example:

# import constants for the days of the week
from matplotlib.dates import MO, TU, WE, TH, FR, SA, SU

# tick on Mondays every week
loc = WeekdayLocator(byweekday=MO, tz=tz)

# tick on Mondays and Saturdays
loc = WeekdayLocator(byweekday=(MO, SA))

In addition, most of the constructors take an interval argument:

# tick on Mondays every second week
loc = WeekdayLocator(byweekday=MO, interval=2)

The rrule locator allows completely general date ticking:

# tick every 5th easter
rule = rrulewrapper(YEARLY, byeaster=1, interval=5)
loc = RRuleLocator(rule)

The available date tickers are:

  • MicrosecondLocator: Locate microseconds.

  • SecondLocator: Locate seconds.

  • MinuteLocator: Locate minutes.

  • HourLocator: Locate hours.

  • DayLocator: Locate specified 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 rrulewrapper. rrulewrapper is a simple wrapper around dateutil’s dateutil.rrule which allow almost arbitrary date tick specifications. See rrule example.

  • AutoDateLocator: On autoscale, this class picks the best DateLocator (e.g., RRuleLocator) to set the view limits and the tick locations. If called with interval_multiples=True it will make ticks line up with sensible multiples of the tick intervals. For example, if the interval is 4 hours, it will pick hours 0, 4, 8, etc. as ticks. This behaviour is not guaranteed by default.

Date formatters

The available date formatters are:

  • AutoDateFormatter: attempts to figure out the best format to use. This is most useful when used with the AutoDateLocator.

  • ConciseDateFormatter: also attempts to figure out the best format to use, and to make the format as compact as possible while still having complete date information. This is most useful when used with the AutoDateLocator.

  • DateFormatter: use ~datetime.datetime.strftime format strings.

Functions

  • datestr2num(): Convert a date string to a datenum using dateutil.parser.parse.

  • date2num(): Convert datetime objects to Matplotlib dates.

  • num2date(): Convert Matplotlib dates to ~datetime.datetime objects.

  • num2timedelta(): Convert number of days to a ~datetime.timedelta object.

  • drange(): Return a sequence of equally spaced Matplotlib dates.

  • set_epoch(): Set the epoch (origin for dates) for datetime calculations.

  • get_epoch(): Get the epoch used by .dates.

matplotlib.dates.datestr2num(d, default=None)

Convert a date string to a datenum using dateutil.parser.parse.

Parameters:
  • d (str or sequence of str) – The dates to convert.

  • default (datetime.datetime, optional) – The default date to use when fields are missing in d.

matplotlib.dates.date2num(d)

Convert datetime objects to Matplotlib dates.

Parameters:

d (datetime.datetime or numpy.datetime64 or sequences of these) –

Returns:

Number of days since the epoch. See .get_epoch for the epoch, which can be changed by :rc:`date.epoch` or .set_epoch. If the epoch is “1970-01-01T00:00:00” (default) then noon Jan 1 1970 (“1970-01-01T12:00:00”) returns 0.5.

Return type:

float or sequence of floats

Notes

The Gregorian calendar is assumed; this is not universal practice. For details see the module docstring.

matplotlib.dates.num2date(x, tz=None)

Convert Matplotlib dates to ~datetime.datetime objects.

Parameters:
  • x (float or sequence of floats) – Number of days (fraction part represents hours, minutes, seconds) since the epoch. See .get_epoch for the epoch, which can be changed by :rc:`date.epoch` or .set_epoch.

  • tz (str or ~datetime.tzinfo, default: :rc:`timezone`) – Timezone of x. If a string, tz is passed to dateutil.tz.

Returns:

Dates are returned in timezone tz.

If x is a sequence, a sequence of ~datetime.datetime objects will be returned.

Return type:

~datetime.datetime or sequence of ~datetime.datetime

Notes

The Gregorian calendar is assumed; this is not universal practice. For details, see the module docstring.

matplotlib.dates.num2timedelta(x)

Convert number of days to a ~datetime.timedelta object.

If x is a sequence, a sequence of ~datetime.timedelta objects will be returned.

Parameters:

x (float, sequence of floats) – Number of days. The fraction part represents hours, minutes, seconds.

Return type:

datetime.timedelta or list[datetime.timedelta]

matplotlib.dates.drange(dstart, dend, delta)

Return a sequence of equally spaced Matplotlib dates.

The dates start at dstart and reach up to, but not including dend. They are spaced by delta.

Parameters:
  • dstart (~datetime.datetime) – The date limits.

  • dend (~datetime.datetime) – The date limits.

  • delta (datetime.timedelta) – Spacing of the dates.

Returns:

A list floats representing Matplotlib dates.

Return type:

numpy.array

matplotlib.dates.set_epoch(epoch)

Set the epoch (origin for dates) for datetime calculations.

The default epoch is :rc:`dates.epoch` (by default 1970-01-01T00:00).

If microsecond accuracy is desired, the date being plotted needs to be within approximately 70 years of the epoch. Matplotlib internally represents dates as days since the epoch, so floating point dynamic range needs to be within a factor of 2^52.

~.dates.set_epoch must be called before any dates are converted (i.e. near the import section) or a RuntimeError will be raised.

See also /gallery/ticks/date_precision_and_epochs.

Parameters:

epoch (str) – valid UTC date parsable by numpy.datetime64 (do not include timezone).

matplotlib.dates.get_epoch()

Get the epoch used by .dates.

Returns:

epoch – String for the epoch (parsable by numpy.datetime64).

Return type:

str

Classes

  • DateFormatter: Format a tick (in days since the epoch) with a

  • ConciseDateFormatter: A .Formatter which attempts to figure out the best format to use for the

  • AutoDateFormatter: A .Formatter which attempts to figure out the best format to use. This

  • DateLocator: Determines the tick locations when plotting dates.

  • RRuleLocator: Determines the tick locations when plotting dates.

  • AutoDateLocator: On autoscale, this class picks the best DateLocator to set the view

  • YearLocator: Make ticks on a given day of each year that is a multiple of base.

  • MonthLocator: Make ticks on occurrences of each month, e.g., 1, 3, 12.

  • WeekdayLocator: Make ticks on occurrences of each weekday.

  • DayLocator: Make ticks on occurrences of each day of the month. For example,

  • HourLocator: Make ticks on occurrences of each hour.

  • MinuteLocator: Make ticks on occurrences of each minute.

  • SecondLocator: Make ticks on occurrences of each second.

  • MicrosecondLocator: Make ticks on regular intervals of one or more microsecond(s).

  • rrule: That’s the base of the rrule operation. It accepts all the keywords

  • relativedelta: The relativedelta type is designed to be applied to an existing datetime and

  • DateConverter: Converter for datetime.date and datetime.datetime data, or for

  • ConciseDateConverter: Converter for datetime.date and datetime.datetime data, or for

  • rrulewrapper: A simple wrapper around a dateutil.rrule allowing flexible

class matplotlib.dates.DateFormatter(fmt, tz=None, *, usetex=None)

Format a tick (in days since the epoch) with a ~datetime.datetime.strftime format string.

Inheritance

digraph inheritance6d401a7d1f { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateFormatter" [URL="#matplotlib.dates.DateFormatter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Format a tick (in days since the epoch) with a"]; "Formatter" -> "DateFormatter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Formatter" [URL="matplotlib.ticker.html#matplotlib.ticker.Formatter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Create a string based on a tick value and location."]; "TickHelper" -> "Formatter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.ConciseDateFormatter(locator, tz=None, formats=None, offset_formats=None, zero_formats=None, show_offset=True, *, usetex=None)

A .Formatter which attempts to figure out the best format to use for the date, and to make it as compact as possible, but still be complete. This is most useful when used with the AutoDateLocator:

>>> locator = AutoDateLocator()
>>> formatter = ConciseDateFormatter(locator)
Parameters:
  • locator (.ticker.Locator) – Locator that this axis is using.

  • tz (str or ~datetime.tzinfo, default: :rc:`timezone`) – Ticks timezone, passed to .dates.num2date.

  • formats (list of 6 strings, optional) – Format strings for 6 levels of tick labelling: mostly years, months, days, hours, minutes, and seconds. Strings use the same format codes as ~datetime.datetime.strftime. Default is ['%Y', '%b', '%d', '%H:%M', '%H:%M', '%S.%f']

  • zero_formats (list of 6 strings, optional) – Format strings for tick labels that are “zeros” for a given tick level. For instance, if most ticks are months, ticks around 1 Jan 2005 will be labeled “Dec”, “2005”, “Feb”. The default is ['', '%Y', '%b', '%b-%d', '%H:%M', '%H:%M']

  • offset_formats (list of 6 strings, optional) –

    Format strings for the 6 levels that is applied to the “offset” string found on the right side of an x-axis, or top of a y-axis. Combined with the tick labels this should completely specify the date. The default is:

    ['', '%Y', '%Y-%b', '%Y-%b-%d', '%Y-%b-%d', '%Y-%b-%d %H:%M']
    

  • show_offset (bool, default: True) – Whether to show the offset or not.

  • usetex (bool, default: :rc:`text.usetex`) – To enable/disable the use of TeX’s math mode for rendering the results of the formatter.

Examples

See /gallery/ticks/date_concise_formatter

Inheritance

digraph inheritanceed7a94b881 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ConciseDateFormatter" [URL="#matplotlib.dates.ConciseDateFormatter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A `.Formatter` which attempts to figure out the best format to use for the"]; "Formatter" -> "ConciseDateFormatter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Formatter" [URL="matplotlib.ticker.html#matplotlib.ticker.Formatter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Create a string based on a tick value and location."]; "TickHelper" -> "Formatter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
format_data_short(value)

Return a short string version of the tick value.

Defaults to the position-independent long value.

format_ticks(values)

Return the tick labels for all the ticks at once.

class matplotlib.dates.AutoDateFormatter(locator, tz=None, defaultfmt='%Y-%m-%d', *, usetex=None)

A .Formatter which attempts to figure out the best format to use. This is most useful when used with the AutoDateLocator.

.AutoDateFormatter has a .scale dictionary that maps tick scales (the interval in days between one major tick) to format strings; this dictionary defaults to

self.scaled = {
    DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
    DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
    1: rcParams['date.autoformatter.day'],
    1 / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
    1 / MINUTES_PER_DAY: rcParams['date.autoformatter.minute'],
    1 / SEC_PER_DAY: rcParams['date.autoformatter.second'],
    1 / MUSECONDS_PER_DAY: rcParams['date.autoformatter.microsecond'],
}

The formatter uses the format string corresponding to the lowest key in the dictionary that is greater or equal to the current scale. Dictionary entries can be customized:

locator = AutoDateLocator()
formatter = AutoDateFormatter(locator)
formatter.scaled[1/(24*60)] = '%M:%S' # only show min and sec

Custom callables can also be used instead of format strings. The following example shows how to use a custom format function to strip trailing zeros from decimal seconds and adds the date to the first ticklabel:

def my_format_function(x, pos=None):
    x = matplotlib.dates.num2date(x)
    if pos == 0:
        fmt = '%D %H:%M:%S.%f'
    else:
        fmt = '%H:%M:%S.%f'
    label = x.strftime(fmt)
    label = label.rstrip("0")
    label = label.rstrip(".")
    return label

formatter.scaled[1/(24*60)] = my_format_function

Inheritance

digraph inheritance373821d336 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoDateFormatter" [URL="#matplotlib.dates.AutoDateFormatter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A `.Formatter` which attempts to figure out the best format to use. This"]; "Formatter" -> "AutoDateFormatter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Formatter" [URL="matplotlib.ticker.html#matplotlib.ticker.Formatter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Create a string based on a tick value and location."]; "TickHelper" -> "Formatter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.DateLocator(tz=None)

Determines the tick locations when plotting dates.

This class is subclassed by other Locators and is not meant to be used on its own.

Inheritance

digraph inheritancebddd93a9cc { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
datalim_to_dt()

Convert axis data interval to datetime objects.

nonsingular(vmin, vmax)

Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0).

set_tzinfo(tz)

Set timezone info.

Parameters:

tz (str or ~datetime.tzinfo, default: :rc:`timezone`) – Ticks timezone. If a string, tz is passed to dateutil.tz.

viewlim_to_dt()

Convert the view interval to datetime objects.

class matplotlib.dates.RRuleLocator(o, tz=None)

Inheritance

digraph inheritanceebd1e318db { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
tick_values(vmin, vmax)

Return the values of the located ticks given vmin and vmax.

Note

To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance:

>>> print(type(loc))
<type 'Locator'>
>>> print(loc())
[1, 2, 3, 4]
class matplotlib.dates.AutoDateLocator(tz=None, minticks=5, maxticks=None, interval_multiples=True)

On autoscale, this class picks the best DateLocator to set the view limits and the tick locations.

intervald

Mapping of tick frequencies to multiples allowed for that ticking. The default is

self.intervald = {
    YEARLY  : [1, 2, 4, 5, 10, 20, 40, 50, 100, 200, 400, 500,
               1000, 2000, 4000, 5000, 10000],
    MONTHLY : [1, 2, 3, 4, 6],
    DAILY   : [1, 2, 3, 7, 14, 21],
    HOURLY  : [1, 2, 3, 4, 6, 12],
    MINUTELY: [1, 5, 10, 15, 30],
    SECONDLY: [1, 5, 10, 15, 30],
    MICROSECONDLY: [1, 2, 5, 10, 20, 50, 100, 200, 500,
                    1000, 2000, 5000, 10000, 20000, 50000,
                    100000, 200000, 500000, 1000000],
}

where the keys are defined in dateutil.rrule.

The interval is used to specify multiples that are appropriate for the frequency of ticking. For instance, every 7 days is sensible for daily ticks, but for minutes/seconds, 15 or 30 make sense.

When customizing, you should only modify the values for the existing keys. You should not add or delete entries.

Example for forcing ticks every 3 hours:

locator = AutoDateLocator()
locator.intervald[HOURLY] = [3]  # only show every 3 hours
Type:

dict

Inheritance

digraph inheritanced962e7890e { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "AutoDateLocator" [URL="#matplotlib.dates.AutoDateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="On autoscale, this class picks the best `DateLocator` to set the view"]; "DateLocator" -> "AutoDateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
get_locator(dmin, dmax)

Pick the best locator based on a distance.

nonsingular(vmin, vmax)

Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0).

tick_values(vmin, vmax)

Return the values of the located ticks given vmin and vmax.

Note

To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance:

>>> print(type(loc))
<type 'Locator'>
>>> print(loc())
[1, 2, 3, 4]
class matplotlib.dates.YearLocator(base=1, month=1, day=1, tz=None)

Make ticks on a given day of each year that is a multiple of base.

Examples:

# Tick every year on Jan 1st
locator = YearLocator()

# Tick every 5 years on July 4th
locator = YearLocator(5, month=7, day=4)

Inheritance

digraph inheritance591b134f88 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "YearLocator" [URL="#matplotlib.dates.YearLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on a given day of each year that is a multiple of base."]; "RRuleLocator" -> "YearLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class matplotlib.dates.MonthLocator(bymonth=None, bymonthday=1, interval=1, tz=None)

Make ticks on occurrences of each month, e.g., 1, 3, 12.

Inheritance

digraph inheritance56aaf3ceab { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MonthLocator" [URL="#matplotlib.dates.MonthLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on occurrences of each month, e.g., 1, 3, 12."]; "RRuleLocator" -> "MonthLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.WeekdayLocator(byweekday=1, interval=1, tz=None)

Make ticks on occurrences of each weekday.

Inheritance

digraph inheritanceaa5175fe8c { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "WeekdayLocator" [URL="#matplotlib.dates.WeekdayLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on occurrences of each weekday."]; "RRuleLocator" -> "WeekdayLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
class matplotlib.dates.DayLocator(bymonthday=None, interval=1, tz=None)

Make ticks on occurrences of each day of the month. For example, 1, 15, 30.

Inheritance

digraph inheritancedbbd616160 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "DayLocator" [URL="#matplotlib.dates.DayLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on occurrences of each day of the month. For example,"]; "RRuleLocator" -> "DayLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.HourLocator(byhour=None, interval=1, tz=None)

Make ticks on occurrences of each hour.

Inheritance

digraph inheritance4abea86079 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "HourLocator" [URL="#matplotlib.dates.HourLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on occurrences of each hour."]; "RRuleLocator" -> "HourLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.MinuteLocator(byminute=None, interval=1, tz=None)

Make ticks on occurrences of each minute.

Inheritance

digraph inheritance75d30af3de { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MinuteLocator" [URL="#matplotlib.dates.MinuteLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on occurrences of each minute."]; "RRuleLocator" -> "MinuteLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.SecondLocator(bysecond=None, interval=1, tz=None)

Make ticks on occurrences of each second.

Inheritance

digraph inheritance6a7636a651 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "RRuleLocator" [URL="#matplotlib.dates.RRuleLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateLocator" -> "RRuleLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "SecondLocator" [URL="#matplotlib.dates.SecondLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on occurrences of each second."]; "RRuleLocator" -> "SecondLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
class matplotlib.dates.MicrosecondLocator(interval=1, tz=None)

Make ticks on regular intervals of one or more microsecond(s).

Note

By default, Matplotlib uses a floating point representation of time in days since the epoch, so plotting data with microsecond time resolution does not work well for dates that are far (about 70 years) from the epoch (check with ~.dates.get_epoch).

If you want sub-microsecond resolution time plots, it is strongly recommended to use floating point seconds, not datetime-like time representation.

If you really must use datetime.datetime() or similar and still need microsecond precision, change the time origin via .dates.set_epoch to something closer to the dates being plotted. See /gallery/ticks/date_precision_and_epochs.

Inheritance

digraph inheritance77e98ed752 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "DateLocator" [URL="#matplotlib.dates.DateLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determines the tick locations when plotting dates."]; "Locator" -> "DateLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "Locator" [URL="matplotlib.ticker.html#matplotlib.ticker.Locator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Determine the tick locations;"]; "TickHelper" -> "Locator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "MicrosecondLocator" [URL="#matplotlib.dates.MicrosecondLocator",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Make ticks on regular intervals of one or more microsecond(s)."]; "DateLocator" -> "MicrosecondLocator" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TickHelper" [URL="matplotlib.ticker.html#matplotlib.ticker.TickHelper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }
tick_values(vmin, vmax)

Return the values of the located ticks given vmin and vmax.

Note

To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance:

>>> print(type(loc))
<type 'Locator'>
>>> print(loc())
[1, 2, 3, 4]
class matplotlib.dates.rrule(freq, dtstart=None, interval=1, wkst=None, count=None, until=None, bysetpos=None, bymonth=None, bymonthday=None, byyearday=None, byeaster=None, byweekno=None, byweekday=None, byhour=None, byminute=None, bysecond=None, cache=False)

That’s the base of the rrule operation. It accepts all the keywords defined in the RFC as its constructor parameters (except byday, which was renamed to byweekday) and more. The constructor prototype is:

rrule(freq)

Where freq must be one of YEARLY, MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY, or SECONDLY.

Note

Per RFC section 3.3.10, recurrence instances falling on invalid dates and times are ignored rather than coerced:

Recurrence rules may generate recurrence instances with an invalid date (e.g., February 30) or nonexistent local time (e.g., 1:30 AM on a day where the local time is moved forward by an hour at 1:00 AM). Such recurrence instances MUST be ignored and MUST NOT be counted as part of the recurrence set.

This can lead to possibly surprising behavior when, for example, the start date occurs at the end of the month:

>>> from dateutil.rrule import rrule, MONTHLY
>>> from datetime import datetime
>>> start_date = datetime(2014, 12, 31)
>>> list(rrule(freq=MONTHLY, count=4, dtstart=start_date))
... 
[datetime.datetime(2014, 12, 31, 0, 0),
 datetime.datetime(2015, 1, 31, 0, 0),
 datetime.datetime(2015, 3, 31, 0, 0),
 datetime.datetime(2015, 5, 31, 0, 0)]

Additionally, it supports the following keyword arguments:

Parameters:
  • dtstart – The recurrence start. Besides being the base for the recurrence, missing parameters in the final recurrence instances will also be extracted from this date. If not given, datetime.now() will be used instead.

  • interval – The interval between each freq iteration. For example, when using YEARLY, an interval of 2 means once every two years, but with HOURLY, it means once every two hours. The default interval is 1.

  • wkst – The week start day. Must be one of the MO, TU, WE constants, or an integer, specifying the first day of the week. This will affect recurrences based on weekly periods. The default week start is got from calendar.firstweekday(), and may be modified by calendar.setfirstweekday().

  • count

    If given, this determines how many occurrences will be generated.

    Note

    As of version 2.5.0, the use of the keyword until in conjunction with count is deprecated, to make sure dateutil is fully compliant with RFC-5545 Sec. 3.3.10. Therefore, until and count must not occur in the same call to rrule.

  • until

    If given, this must be a datetime instance specifying the upper-bound limit of the recurrence. The last recurrence in the rule is the greatest datetime that is less than or equal to the value specified in the until parameter.

    Note

    As of version 2.5.0, the use of the keyword until in conjunction with count is deprecated, to make sure dateutil is fully compliant with RFC-5545 Sec. 3.3.10. Therefore, until and count must not occur in the same call to rrule.

  • bysetpos – If given, it must be either an integer, or a sequence of integers, positive or negative. Each given integer will specify an occurrence number, corresponding to the nth occurrence of the rule inside the frequency period. For example, a bysetpos of -1 if combined with a MONTHLY frequency, and a byweekday of (MO, TU, WE, TH, FR), will result in the last work day of every month.

  • bymonth – If given, it must be either an integer, or a sequence of integers, meaning the months to apply the recurrence to.

  • bymonthday – If given, it must be either an integer, or a sequence of integers, meaning the month days to apply the recurrence to.

  • byyearday – If given, it must be either an integer, or a sequence of integers, meaning the year days to apply the recurrence to.

  • byeaster – If given, it must be either an integer, or a sequence of integers, positive or negative. Each integer will define an offset from the Easter Sunday. Passing the offset 0 to byeaster will yield the Easter Sunday itself. This is an extension to the RFC specification.

  • byweekno – If given, it must be either an integer, or a sequence of integers, meaning the week numbers to apply the recurrence to. Week numbers have the meaning described in ISO8601, that is, the first week of the year is that containing at least four days of the new year.

  • byweekday – If given, it must be either an integer (0 == MO), a sequence of integers, one of the weekday constants (MO, TU, etc), or a sequence of these constants. When given, these variables will define the weekdays where the recurrence will be applied. It’s also possible to use an argument n for the weekday instances, which will mean the nth occurrence of this weekday in the period. For example, with MONTHLY, or with YEARLY and BYMONTH, using FR(+1) in byweekday will specify the first friday of the month where the recurrence happens. Notice that in the RFC documentation, this is specified as BYDAY, but was renamed to avoid the ambiguity of that keyword.

  • byhour – If given, it must be either an integer, or a sequence of integers, meaning the hours to apply the recurrence to.

  • byminute – If given, it must be either an integer, or a sequence of integers, meaning the minutes to apply the recurrence to.

  • bysecond – If given, it must be either an integer, or a sequence of integers, meaning the seconds to apply the recurrence to.

  • cache – If given, it must be a boolean value specifying to enable or disable caching of results. If you will use the same rrule instance multiple times, enabling caching will improve the performance considerably.

Inheritance

digraph inheritancec7488dbf1c { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "rrule" [URL="#matplotlib.dates.rrule",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="That's the base of the rrule operation. It accepts all the keywords"]; "rrulebase" -> "rrule" [arrowsize=0.5,style="setlinewidth(0.5)"]; "rrulebase" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; }
replace(**kwargs)

Return new rrule with same attributes except for those attributes given new values by whichever keyword arguments are specified.

class matplotlib.dates.relativedelta(dt1=None, dt2=None, years=0, months=0, days=0, leapdays=0, weeks=0, hours=0, minutes=0, seconds=0, microseconds=0, year=None, month=None, day=None, weekday=None, yearday=None, nlyearday=None, hour=None, minute=None, second=None, microsecond=None)

The relativedelta type is designed to be applied to an existing datetime and can replace specific components of that datetime, or represents an interval of time.

It is based on the specification of the excellent work done by M.-A. Lemburg in his mx.DateTime extension. However, notice that this type does NOT implement the same algorithm as his work. Do NOT expect it to behave like mx.DateTime’s counterpart.

There are two different ways to build a relativedelta instance. The first one is passing it two date/datetime classes:

relativedelta(datetime1, datetime2)

The second one is passing it any number of the following keyword arguments:

relativedelta(arg1=x,arg2=y,arg3=z...)

year, month, day, hour, minute, second, microsecond:
    Absolute information (argument is singular); adding or subtracting a
    relativedelta with absolute information does not perform an arithmetic
    operation, but rather REPLACES the corresponding value in the
    original datetime with the value(s) in relativedelta.

years, months, weeks, days, hours, minutes, seconds, microseconds:
    Relative information, may be negative (argument is plural); adding
    or subtracting a relativedelta with relative information performs
    the corresponding arithmetic operation on the original datetime value
    with the information in the relativedelta.

weekday:
    One of the weekday instances (MO, TU, etc) available in the
    relativedelta module. These instances may receive a parameter N,
    specifying the Nth weekday, which could be positive or negative
    (like MO(+1) or MO(-2)). Not specifying it is the same as specifying
    +1. You can also use an integer, where 0=MO. This argument is always
    relative e.g. if the calculated date is already Monday, using MO(1)
    or MO(-1) won't change the day. To effectively make it absolute, use
    it in combination with the day argument (e.g. day=1, MO(1) for first
    Monday of the month).

leapdays:
    Will add given days to the date found, if year is a leap
    year, and the date found is post 28 of february.

yearday, nlyearday:
    Set the yearday or the non-leap year day (jump leap days).
    These are converted to day/month/leapdays information.

There are relative and absolute forms of the keyword arguments. The plural is relative, and the singular is absolute. For each argument in the order below, the absolute form is applied first (by setting each attribute to that value) and then the relative form (by adding the value to the attribute).

The order of attributes considered when this relativedelta is added to a datetime is:

  1. Year

  2. Month

  3. Day

  4. Hours

  5. Minutes

  6. Seconds

  7. Microseconds

Finally, weekday is applied, using the rule described above.

For example

>>> from datetime import datetime
>>> from dateutil.relativedelta import relativedelta, MO
>>> dt = datetime(2018, 4, 9, 13, 37, 0)
>>> delta = relativedelta(hours=25, day=1, weekday=MO(1))
>>> dt + delta
datetime.datetime(2018, 4, 2, 14, 37)

First, the day is set to 1 (the first of the month), then 25 hours are added, to get to the 2nd day and 14th hour, finally the weekday is applied, but since the 2nd is already a Monday there is no effect.

Inheritance

digraph inheritance5fd4bdbc60 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "relativedelta" [URL="#matplotlib.dates.relativedelta",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The relativedelta type is designed to be applied to an existing datetime and"]; }
normalized()

Return a version of this object represented entirely using integer values for the relative attributes.

>>> relativedelta(days=1.5, hours=2).normalized()
relativedelta(days=+1, hours=+14)
Returns:

Returns a dateutil.relativedelta.relativedelta object.

class matplotlib.dates.DateConverter(*, interval_multiples=True)

Converter for datetime.date and datetime.datetime data, or for date/time data represented as it would be converted by date2num.

The ‘unit’ tag for such data is None or a ~datetime.tzinfo instance.

Inheritance

digraph inheritance002afadc70 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ConversionInterface" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="The minimal interface for a converter to take custom data types (or"]; "DateConverter" [URL="#matplotlib.dates.DateConverter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Converter for `datetime.date` and `datetime.datetime` data, or for"]; "ConversionInterface" -> "DateConverter" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
axisinfo(unit, axis)

Return the ~matplotlib.units.AxisInfo for unit.

unit is a ~datetime.tzinfo instance or None. The axis argument is required but not used.

static convert(value, unit, axis)

If value is not already a number or sequence of numbers, convert it with date2num.

The unit and axis arguments are not used.

static default_units(x, axis)

Return the ~datetime.tzinfo instance of x or of its first element, or None

class matplotlib.dates.ConciseDateConverter(formats=None, zero_formats=None, offset_formats=None, show_offset=True, *, interval_multiples=True)

Inheritance

digraph inheritance215cefe5e2 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ConciseDateConverter" [URL="#matplotlib.dates.ConciseDateConverter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "DateConverter" -> "ConciseDateConverter" [arrowsize=0.5,style="setlinewidth(0.5)"]; "ConversionInterface" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="The minimal interface for a converter to take custom data types (or"]; "DateConverter" [URL="#matplotlib.dates.DateConverter",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Converter for `datetime.date` and `datetime.datetime` data, or for"]; "ConversionInterface" -> "DateConverter" [arrowsize=0.5,style="setlinewidth(0.5)"]; }
axisinfo(unit, axis)

Return the ~matplotlib.units.AxisInfo for unit.

unit is a ~datetime.tzinfo instance or None. The axis argument is required but not used.

class matplotlib.dates.rrulewrapper(freq, tzinfo=None, **kwargs)

A simple wrapper around a dateutil.rrule allowing flexible date tick specifications.

Inheritance

digraph inheritance299d9a1c39 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "rrulewrapper" [URL="#matplotlib.dates.rrulewrapper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A simple wrapper around a `dateutil.rrule` allowing flexible"]; }
set(**kwargs)

Set parameters for an existing wrapper.

Variables

matplotlib.dates.MO

This version of weekday does not allow n = 0.

MO
matplotlib.dates.TU

This version of weekday does not allow n = 0.

TU
matplotlib.dates.WE

This version of weekday does not allow n = 0.

WE
matplotlib.dates.TH

This version of weekday does not allow n = 0.

TH
matplotlib.dates.FR

This version of weekday does not allow n = 0.

FR
matplotlib.dates.SA

This version of weekday does not allow n = 0.

SA
matplotlib.dates.SU

This version of weekday does not allow n = 0.

SU
matplotlib.dates.YEARLY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

0
matplotlib.dates.MONTHLY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

1
matplotlib.dates.WEEKLY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

2
matplotlib.dates.DAILY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

3
matplotlib.dates.HOURLY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

4
matplotlib.dates.MINUTELY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

5
matplotlib.dates.SECONDLY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

6
matplotlib.dates.MICROSECONDLY

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4

7