You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
<divid="unreleased-message"> You are reading an old version of the documentation (v3.1.3). For the latest version see <ahref="https://matplotlib.org/stable/api/dates_api.html">https://matplotlib.org/stable/api/dates_api.html</a></div>
<h1><codeclass="docutils literal notranslate"><spanclass="pre">matplotlib.dates</span></code><aclass="headerlink" href="#matplotlib-dates" title="Permalink to this headline">¶</a></h1>
<divclass="graphviz"><imgsrc="../_images/inheritance-d77fed2f606dd3ef2d455455d9d08a84da240064.png" alt="Inheritance diagram of matplotlib.dates" usemap="#inheritance1bda3e63b5" class="inheritance graphviz" /></div>
<areashape="rect" id="node1" href="#matplotlib.dates.AutoDateFormatter" target="_top" title="This class attempts to figure out the best format to use.  This is" alt="" coords="325,125,445,146"/>
<areashape="rect" id="node2" href="ticker_api.html#matplotlib.ticker.Formatter" target="_top" title="Create a string based on a tick value and location." alt="" coords="188,206,259,227"/>
<areashape="rect" id="node7" href="#matplotlib.dates.ConciseDateFormatter" target="_top" title="This class attempts to figure out the best format to use for the" alt="" coords="316,166,454,187"/>
<areashape="rect" id="node9" href="#matplotlib.dates.DateFormatter" target="_top" title="Format a tick (in seconds since the epoch) with a `strftime` format string." alt="" coords="337,206,433,227"/>
<areashape="rect" id="node15" href="#matplotlib.dates.IndexDateFormatter" target="_top" title="Use with :class:`~matplotlib.ticker.IndexLocator` to cycle format" alt="" coords="322,247,448,267"/>
<areashape="rect" id="node3" href="#matplotlib.dates.AutoDateLocator" target="_top" title="On autoscale, this class picks the best" alt="" coords="502,226,609,247"/>
<areashape="rect" id="node4" href="#matplotlib.dates.DateLocator" target="_top" title="Determines the tick locations when plotting dates." alt="" coords="344,287,427,308"/>
<areashape="rect" id="node16" href="#matplotlib.dates.MicrosecondLocator" target="_top" title="Make ticks on regular intervals of one or more microsecond(s)." alt="" coords="493,307,617,327"/>
<areashape="rect" id="node21" href="#matplotlib.dates.YearLocator" target="_top" title="Make ticks on a given day of each year that is a multiple of base." alt="" coords="515,347,595,368"/>
<areashape="rect" id="node8" href="units_api.html#matplotlib.units.ConversionInterface" target="_top" title="The minimal interface for a converter to take custom data types (or" alt="" coords="4,85,130,106"/>
<areashape="rect" id="node10" href="ticker_api.html#matplotlib.ticker.Locator" target="_top" title="Determine the tick locations;" alt="" coords="194,267,253,288"/>
<areashape="rect" id="node11" href="#matplotlib.dates.DayLocator" target="_top" title="Make ticks on occurrences of each day of the month.  For example," alt="" coords="671,165,749,185"/>
<areashape="rect" id="node14" href="#matplotlib.dates.HourLocator" target="_top" title="Make ticks on occurrences of each hour." alt="" coords="669,205,752,226"/>
<areashape="rect" id="node17" href="#matplotlib.dates.MinuteLocator" target="_top" title="Make ticks on occurrences of each minute." alt="" coords="663,245,757,266"/>
<areashape="rect" id="node18" href="#matplotlib.dates.MonthLocator" target="_top" title="Make ticks on occurrences of each month, e.g., 1, 3, 12." alt="" coords="665,286,755,307"/>
<areashape="rect" id="node19" href="#matplotlib.dates.SecondLocator" target="_top" title="Make ticks on occurrences of each second." alt="" coords="662,326,758,347"/>
<areashape="rect" id="node20" href="#matplotlib.dates.WeekdayLocator" target="_top" title="Make ticks on occurrences of each weekday." alt="" coords="657,367,764,387"/>
</map><spanclass="target" id="module-matplotlib.dates"></span><p>Matplotlib provides sophisticated date plotting capabilities, standing on the
shoulders of python <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#module-datetime" title="(in Python v3.8)"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">datetime</span></code></a> and the add-on module <codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">dateutil</span></code>.</p>
<divclass="section" id="matplotlib-date-format">
<spanid="date-format"></span><h2>Matplotlib date format<aclass="headerlink" href="#matplotlib-date-format" title="Permalink to this headline">¶</a></h2>
<p>Matplotlib represents dates using floating point numbers specifying the number
of days since 0001-01-01 UTC, plus 1. For example, 0001-01-01, 06:00 is 1.25,
not 0.25. Values < 1, i.e. dates before 0001-01-01 UTC, are not supported.</p>
<p>There are a number of helper functions to convert between <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#module-datetime" title="(in Python v3.8)"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">datetime</span></code></a>
<td>Convert a date string to a datenum using <codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">dateutil.parser.parse()</span></code>.</td>
<td>Convert number of days to a <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(in Python v3.8)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">timedelta</span></code></a> object.</td>
<td>Convert mx <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">datetime</span></code> instance (or sequence of mx instances) to the new date format.</td>
<p>All the Matplotlib date converters, tickers and formatters are timezone aware.
If no explicit timezone is provided, <codeclass="docutils literal notranslate"><aclass="reference external" href="../tutorials/introductory/customizing.html?highlight=timezone#a-sample-matplotlibrc-file"><spanclass="pre">rcParams["timezone"]</span></a></code> (default: 'UTC') is assumed. If you want to
use a custom time zone, pass a <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.tzinfo" title="(in Python v3.8)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">datetime.tzinfo</span></code></a> instance with the tz keyword
argument to <aclass="reference internal" href="#matplotlib.dates.num2date" title="matplotlib.dates.num2date"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">num2date</span></code></a>, <aclass="reference internal" href="_as_gen/matplotlib.axes.Axes.plot_date.html#matplotlib.axes.Axes.plot_date" title="matplotlib.axes.Axes.plot_date"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">plot_date</span></code></a>, and any custom date tickers or
locators you create.</p>
<p>A wide range of specific and general purpose date tick locators and
formatters are provided in this module. See
<aclass="reference internal" href="ticker_api.html#module-matplotlib.ticker" title="matplotlib.ticker"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">matplotlib.ticker</span></code></a> for general information on tick locators
and formatters. These are described below.</p>
<p>The <aclass="reference external" href="https://dateutil.readthedocs.io">dateutil</a> module provides additional code to handle date ticking, making it
easy to place ticks on any kinds of dates. See examples below.</p>
</div>
<divclass="section" id="date-tickers">
<h2>Date tickers<aclass="headerlink" href="#date-tickers" title="Permalink to this headline">¶</a></h2>
<p>Most of the date tickers can locate single or multiple values. For
example:</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="c1"># import constants for the days of the week</span>
<li><aclass="reference internal" href="#matplotlib.dates.DayLocator" title="matplotlib.dates.DayLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">DayLocator</span></code></a>: locate specified days of the month</li>
<li><aclass="reference internal" href="#matplotlib.dates.WeekdayLocator" title="matplotlib.dates.WeekdayLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">WeekdayLocator</span></code></a>: Locate days of the week, e.g., MO, TU</li>
<li><aclass="reference internal" href="#matplotlib.dates.YearLocator" title="matplotlib.dates.YearLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">YearLocator</span></code></a>: locate years that are multiples of base</li>
<li><aclass="reference internal" href="#matplotlib.dates.RRuleLocator" title="matplotlib.dates.RRuleLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">RRuleLocator</span></code></a>: locate using a <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">matplotlib.dates.rrulewrapper</span></code>.
<codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">rrulewrapper</span></code> is a simple wrapper around <aclass="reference external" href="https://dateutil.readthedocs.io">dateutil</a>'s <aclass="reference external" href="https://dateutil.readthedocs.io/en/stable/rrule.html#module-dateutil.rrule" title="(in dateutil v2.8.1)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">dateutil.rrule</span></code></a> which
allow almost arbitrary date tick specifications. See <aclass="reference internal" href="../gallery/ticks_and_spines/date_demo_rrule.html"><spanclass="doc">rrule example</span></a>.</li>
<li><aclass="reference internal" href="#matplotlib.dates.AutoDateLocator" title="matplotlib.dates.AutoDateLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">AutoDateLocator</span></code></a>: On autoscale, this class picks the best <aclass="reference internal" href="#matplotlib.dates.DateLocator" title="matplotlib.dates.DateLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">DateLocator</span></code></a>
(e.g., <aclass="reference internal" href="#matplotlib.dates.RRuleLocator" title="matplotlib.dates.RRuleLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">RRuleLocator</span></code></a>) to set the view limits and the tick locations. If
called with <codeclass="docutils literal notranslate"><spanclass="pre">interval_multiples=True</span></code> it will make ticks line up with
sensible multiples of the tick intervals. E.g. if the interval is 4 hours,
it will pick hours 0, 4, 8, etc as ticks. This behaviour is not guaranteed
by default.</li>
</ul>
</div>
<divclass="section" id="date-formatters">
<h2>Date formatters<aclass="headerlink" href="#date-formatters" title="Permalink to this headline">¶</a></h2>
<p>The available date formatters are:</p>
<ulclass="simple">
<li><aclass="reference internal" href="#matplotlib.dates.AutoDateFormatter" title="matplotlib.dates.AutoDateFormatter"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">AutoDateFormatter</span></code></a>: attempts to figure out the best format to use. This is
most useful when used with the <aclass="reference internal" href="#matplotlib.dates.AutoDateLocator" title="matplotlib.dates.AutoDateLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">AutoDateLocator</span></code></a>.</li>
<li><aclass="reference internal" href="#matplotlib.dates.ConciseDateFormatter" title="matplotlib.dates.ConciseDateFormatter"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">ConciseDateFormatter</span></code></a>: 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 <aclass="reference internal" href="#matplotlib.dates.AutoDateLocator" title="matplotlib.dates.AutoDateLocator"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">AutoDateLocator</span></code></a>.</li>
<li><aclass="reference internal" href="#matplotlib.dates.DateFormatter" title="matplotlib.dates.DateFormatter"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">DateFormatter</span></code></a>: use <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">strftime</span></code> format strings.</li>
<li><aclass="reference internal" href="#matplotlib.dates.IndexDateFormatter" title="matplotlib.dates.IndexDateFormatter"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">IndexDateFormatter</span></code></a>: date plots with implicit <em>x</em> indexing.</li>
</ul>
<dlclass="function">
<dtid="matplotlib.dates.datestr2num">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">datestr2num</code><spanclass="sig-paren">(</span><em>d</em>, <em>default=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#datestr2num"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.datestr2num" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert a date string to a datenum using <codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">dateutil.parser.parse()</span></code>.</p>
<dd><pclass="first last">The default date to use when fields are missing in <em>d</em>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.dates.date2num">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">date2num</code><spanclass="sig-paren">(</span><em>d</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#date2num"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.date2num" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert datetime objects to Matplotlib dates.</p>
<dt><strong>d</strong><spanclass="classifier-delimiter">:</span><spanclass="classifier"><aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime" title="(in Python v3.8)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">datetime.datetime</span></code></a> or <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">numpy.datetime64</span></code> or sequences of these</span></dt>
<dd></dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dt>float or sequence of floats</dt>
<dd><pclass="first last">Number of days (fraction part represents hours, minutes, seconds, ms)
since 0001-01-01 00:00:00 UTC, plus one.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<pclass="rubric">Notes</p>
<p>The addition of one here is a historical artifact. Also, note that the
Gregorian calendar is assumed; this is not universal practice.
For details see the module docstring.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.dates.num2date">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">num2date</code><spanclass="sig-paren">(</span><em>x</em>, <em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#num2date"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.num2date" title="Permalink to this definition">¶</a></dt>
<dd><pclass="first last">Timezone of <em>x</em> (defaults to rcparams <codeclass="docutils literal notranslate"><spanclass="pre">timezone</span></code>).</p>
</dd>
</dl>
</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body"><dlclass="first last docutils">
<dd><pclass="first">Dates are returned in timezone <em>tz</em>.</p>
<pclass="last">If <em>x</em> is a sequence, a sequence of <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">datetime</span></code> objects will
be returned.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<pclass="rubric">Notes</p>
<p>The addition of one here is a historical artifact. Also, note that the
Gregorian calendar is assumed; this is not universal practice.
For details, see the module docstring.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.dates.num2timedelta">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">num2timedelta</code><spanclass="sig-paren">(</span><em>x</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#num2timedelta"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.num2timedelta" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert number of days to a <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(in Python v3.8)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">timedelta</span></code></a> object.</p>
<p>If <em>x</em> is a sequence, a sequence of <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" title="(in Python v3.8)"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">timedelta</span></code></a> objects will
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">drange</code><spanclass="sig-paren">(</span><em>dstart</em>, <em>dend</em>, <em>delta</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#drange"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.drange" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a sequence of equally spaced Matplotlib dates.</p>
<p>The dates start at <em>dstart</em> and reach up to, but not including <em>dend</em>.
<dd><pclass="first last">A list floats representing Matplotlib dates.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.dates.epoch2num">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">epoch2num</code><spanclass="sig-paren">(</span><em>e</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#epoch2num"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.epoch2num" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert an epoch or sequence of epochs to the new date format,
that is days since 0001.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.dates.num2epoch">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">num2epoch</code><spanclass="sig-paren">(</span><em>d</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#num2epoch"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.num2epoch" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert days since 0001 to epoch. <em>d</em> can be a number or sequence.</p>
</dd></dl>
<dlclass="function">
<dtid="matplotlib.dates.mx2num">
<codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">mx2num</code><spanclass="sig-paren">(</span><em>mxdates</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#mx2num"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.mx2num" title="Permalink to this definition">¶</a></dt>
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">DateFormatter</code><spanclass="sig-paren">(</span><em>fmt</em>, <em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateFormatter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateFormatter" title="Permalink to this definition">¶</a></dt>
<p>Format a tick (in seconds since the epoch) with a <aclass="reference internal" href="#matplotlib.dates.DateFormatter.strftime" title="matplotlib.dates.DateFormatter.strftime"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">strftime</span></code></a> format string.</p>
<codeclass="descname">illegal_s</code><emclass="property"> = re.compile('((^|[^%])(%%)*%s)')</em><aclass="headerlink" href="#matplotlib.dates.DateFormatter.illegal_s" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_tzinfo</code><spanclass="sig-paren">(</span><em>self</em>, <em>tz</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateFormatter.set_tzinfo"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateFormatter.set_tzinfo" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="matplotlib.dates.DateFormatter.strftime">
<codeclass="descname">strftime</code><spanclass="sig-paren">(</span><em>self</em>, <em>dt</em>, <em>fmt=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateFormatter.strftime"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateFormatter.strftime" title="Permalink to this definition">¶</a></dt>
<dd><p>[<em>Deprecated</em>] Refer to documentation for <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime" title="(in Python v3.8)"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">datetime.datetime.strftime()</span></code></a></p>
<p><em>fmt</em> is a <aclass="reference external" href="https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime" title="(in Python v3.8)"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">datetime.datetime.strftime()</span></code></a> format string.</p>
<p>Warning: For years before 1900, depending upon the current
locale it is possible that the year displayed with %x might
be incorrect. For years before 100, %y and %Y will yield
zero-padded strings.</p>
<pclass="rubric">Notes</p>
<divclass="deprecated">
<p><spanclass="versionmodified">Deprecated since version 3.0.</span></p>
<codeclass="descname">strftime_pre_1900</code><spanclass="sig-paren">(</span><em>self</em>, <em>dt</em>, <em>fmt=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateFormatter.strftime_pre_1900"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateFormatter.strftime_pre_1900" title="Permalink to this definition">¶</a></dt>
<dd><p>[<em>Deprecated</em>] Call time.strftime for years before 1900 by rolling
forward a multiple of 28 years.</p>
<p><em>fmt</em> is a <aclass="reference internal" href="#matplotlib.dates.DateFormatter.strftime" title="matplotlib.dates.DateFormatter.strftime"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">strftime()</span></code></a> format string.</p>
<p>Dalke: I hope I did this math right. Every 28 years the
calendar repeats, except through century leap years excepting
the 400 year leap years. But only if you're using the Gregorian
calendar.</p>
<pclass="rubric">Notes</p>
<divclass="deprecated">
<p><spanclass="versionmodified">Deprecated since version 3.0.</span></p>
</div>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.ConciseDateFormatter">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">ConciseDateFormatter</code><spanclass="sig-paren">(</span><em>locator</em>, <em>tz=None</em>, <em>formats=None</em>, <em>offset_formats=None</em>, <em>zero_formats=None</em>, <em>show_offset=True</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#ConciseDateFormatter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.ConciseDateFormatter" title="Permalink to this definition">¶</a></dt>
<p>This class 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 <aclass="reference internal" href="#matplotlib.dates.AutoDateLocator" title="matplotlib.dates.AutoDateLocator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">AutoDateLocator</span></code></a>:</p>
<dd><pclass="first last">Whether to show the offset or not. Default is <codeclass="docutils literal notranslate"><spanclass="pre">True</span></code>.</p>
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<pclass="rubric">Examples</p>
<p>See <aclass="reference internal" href="../gallery/ticks_and_spines/date_concise_formatter.html"><spanclass="doc">Formatting date ticks using ConciseDateFormatter</span></a></p>
<codeclass="descname">format_data_short</code><spanclass="sig-paren">(</span><em>self</em>, <em>value</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#ConciseDateFormatter.format_data_short"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.ConciseDateFormatter.format_data_short" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a short string version of the tick value.</p>
<p>Defaults to the position-independent long value.</p>
<codeclass="descname">format_ticks</code><spanclass="sig-paren">(</span><em>self</em>, <em>values</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#ConciseDateFormatter.format_ticks"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.ConciseDateFormatter.format_ticks" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the tick labels for all the ticks at once.</p>
<codeclass="descname">get_offset</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#ConciseDateFormatter.get_offset"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.ConciseDateFormatter.get_offset" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.IndexDateFormatter">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">IndexDateFormatter</code><spanclass="sig-paren">(</span><em>t</em>, <em>fmt</em>, <em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#IndexDateFormatter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.IndexDateFormatter" title="Permalink to this definition">¶</a></dt>
<p>Use with <aclass="reference internal" href="ticker_api.html#matplotlib.ticker.IndexLocator" title="matplotlib.ticker.IndexLocator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">IndexLocator</span></code></a> to cycle format
strings by index.</p>
<p><em>t</em> is a sequence of dates (floating point days). <em>fmt</em> is a
<codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">strftime()</span></code> format string.</p>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.AutoDateFormatter">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">AutoDateFormatter</code><spanclass="sig-paren">(</span><em>locator</em>, <em>tz=None</em>, <em>defaultfmt='%Y-%m-%d'</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateFormatter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateFormatter" title="Permalink to this definition">¶</a></dt>
<p>This class attempts to figure out the best format to use. This is
most useful when used with the <aclass="reference internal" href="#matplotlib.dates.AutoDateLocator" title="matplotlib.dates.AutoDateLocator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">AutoDateLocator</span></code></a>.</p>
<p>The AutoDateFormatter has a scale dictionary that maps the scale
of the tick (the distance in days between one major tick) and a
<spanclass="gp">>>> </span><spanclass="n">formatter</span><spanclass="o">.</span><spanclass="n">scaled</span><spanclass="p">[</span><spanclass="mi">1</span><spanclass="o">/</span><spanclass="p">(</span><spanclass="mf">24.</span><spanclass="o">*</span><spanclass="mf">60.</span><spanclass="p">)]</span><spanclass="o">=</span><spanclass="s1">'%M:%S'</span><spanclass="c1"># only show min and sec</span>
</pre></div>
</div>
<p>A custom <aclass="reference internal" href="ticker_api.html#matplotlib.ticker.FuncFormatter" title="matplotlib.ticker.FuncFormatter"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">FuncFormatter</span></code></a> can also be used.
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
<p>Autoformat the date labels. The default format is the one to use
if none of the values in <codeclass="docutils literal notranslate"><spanclass="pre">self.scaled</span></code> are greater than the unit
returned by <codeclass="docutils literal notranslate"><spanclass="pre">locator._get_unit()</span></code>.</p>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.DateLocator">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">DateLocator</code><spanclass="sig-paren">(</span><em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateLocator"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateLocator" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">datalim_to_dt</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateLocator.datalim_to_dt"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateLocator.datalim_to_dt" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert axis data interval to datetime objects.</p>
</dd></dl>
<dlclass="attribute">
<dtid="matplotlib.dates.DateLocator.hms0d">
<codeclass="descname">hms0d</code><emclass="property"> = {'byhour': 0, 'byminute': 0, 'bysecond': 0}</em><aclass="headerlink" href="#matplotlib.dates.DateLocator.hms0d" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>
<dlclass="method">
<dtid="matplotlib.dates.DateLocator.nonsingular">
<codeclass="descname">nonsingular</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateLocator.nonsingular"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateLocator.nonsingular" title="Permalink to this definition">¶</a></dt>
<dd><p>Given the proposed upper and lower extent, adjust the range
if it is too close to being singular (i.e. a range of ~0).</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.dates.DateLocator.set_tzinfo">
<codeclass="descname">set_tzinfo</code><spanclass="sig-paren">(</span><em>self</em>, <em>tz</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateLocator.set_tzinfo"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateLocator.set_tzinfo" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">viewlim_to_dt</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DateLocator.viewlim_to_dt"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DateLocator.viewlim_to_dt" title="Permalink to this definition">¶</a></dt>
<dd><p>Converts the view interval to datetime objects.</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.RRuleLocator">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">RRuleLocator</code><spanclass="sig-paren">(</span><em>o</em>, <em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#RRuleLocator"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.RRuleLocator" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">autoscale</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#RRuleLocator.autoscale"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.RRuleLocator.autoscale" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the view limits to include the data range.</p>
<emclass="property">static </em><codeclass="descname">get_unit_generic</code><spanclass="sig-paren">(</span><em>freq</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#RRuleLocator.get_unit_generic"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.RRuleLocator.get_unit_generic" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">tick_values</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#RRuleLocator.tick_values"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.RRuleLocator.tick_values" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the values of the located ticks given <strong>vmin</strong> and <strong>vmax</strong>.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<p>To get tick locations with the vmin and vmax values defined
automatically for the associated <codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">axis</span></code> simply call
<aclass="reference internal" href="#matplotlib.dates.DateLocator" title="matplotlib.dates.DateLocator"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">DateLocator</span></code></a> to set the view limits and the tick
locations.</p>
<p><em>minticks</em> is the minimum number of ticks desired, which is used to
select the type of ticking (yearly, monthly, etc.).</p>
<p><em>maxticks</em> is the maximum number of ticks desired, which controls
any interval between ticks (ticking every other, every 3, etc.).
For really fine-grained control, this can be a dictionary mapping
individual rrule frequency constants (YEARLY, MONTHLY, etc.)
to their own maximum number of ticks. This can be used to keep
the number of ticks appropriate to the format chosen in
<aclass="reference internal" href="#matplotlib.dates.AutoDateFormatter" title="matplotlib.dates.AutoDateFormatter"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">AutoDateFormatter</span></code></a>. Any frequency not specified in this
dictionary is given a default value.</p>
<p><em>tz</em> is a <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">tzinfo</span></code> instance.</p>
<p><em>interval_multiples</em> is a boolean that indicates whether ticks
should be chosen to be multiple of the interval. This will lock
ticks to 'nicer' locations. For example, this will force the
ticks to be at hours 0,6,12,18 when hourly ticking is done at
6 hour intervals.</p>
<p>The AutoDateLocator has an interval dictionary that maps the
frequency of the tick (a constant from dateutil.rrule) and a
multiple allowed for that ticking. The default looks like this:</p>
<spanclass="n">locator</span><spanclass="o">.</span><spanclass="n">intervald</span><spanclass="p">[</span><spanclass="n">HOURLY</span><spanclass="p">]</span><spanclass="o">=</span><spanclass="p">[</span><spanclass="mi">3</span><spanclass="p">]</span><spanclass="c1"># only show every 3 hours</span>
<codeclass="descname">autoscale</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateLocator.autoscale"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateLocator.autoscale" title="Permalink to this definition">¶</a></dt>
<dd><p>Try to choose the view limits intelligently.</p>
<codeclass="descname">get_locator</code><spanclass="sig-paren">(</span><em>self</em>, <em>dmin</em>, <em>dmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateLocator.get_locator"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateLocator.get_locator" title="Permalink to this definition">¶</a></dt>
<dd><p>Pick the best locator based on a distance.</p>
<codeclass="descname">nonsingular</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateLocator.nonsingular"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateLocator.nonsingular" title="Permalink to this definition">¶</a></dt>
<dd><p>Given the proposed upper and lower extent, adjust the range
if it is too close to being singular (i.e. a range of ~0).</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.dates.AutoDateLocator.refresh">
<codeclass="descname">refresh</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateLocator.refresh"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateLocator.refresh" title="Permalink to this definition">¶</a></dt>
<dd><p>Refresh internal information based on current limits.</p>
<codeclass="descname">set_axis</code><spanclass="sig-paren">(</span><em>self</em>, <em>axis</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateLocator.set_axis"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateLocator.set_axis" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">tick_values</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#AutoDateLocator.tick_values"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.AutoDateLocator.tick_values" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the values of the located ticks given <strong>vmin</strong> and <strong>vmax</strong>.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<p>To get tick locations with the vmin and vmax values defined
automatically for the associated <codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">axis</span></code> simply call
<p>Mark years that are multiple of base on a given month and day
(default jan 1).</p>
<dlclass="method">
<dtid="matplotlib.dates.YearLocator.autoscale">
<codeclass="descname">autoscale</code><spanclass="sig-paren">(</span><em>self</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#YearLocator.autoscale"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.YearLocator.autoscale" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the view limits to include the data range.</p>
</dd></dl>
<dlclass="method">
<dtid="matplotlib.dates.YearLocator.tick_values">
<codeclass="descname">tick_values</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#YearLocator.tick_values"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.YearLocator.tick_values" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the values of the located ticks given <strong>vmin</strong> and <strong>vmax</strong>.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<p>To get tick locations with the vmin and vmax values defined
automatically for the associated <codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">axis</span></code> simply call
<p>Mark every weekday in <em>byweekday</em>; <em>byweekday</em> can be a number or
sequence.</p>
<p>Elements of <em>byweekday</em> must be one of MO, TU, WE, TH, FR, SA,
SU, the constants from <aclass="reference external" href="https://dateutil.readthedocs.io/en/stable/rrule.html#module-dateutil.rrule" title="(in dateutil v2.8.1)"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">dateutil.rrule</span></code></a>, which have been
imported into the <aclass="reference internal" href="#module-matplotlib.dates" title="matplotlib.dates"><codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">matplotlib.dates</span></code></a> namespace.</p>
<p><em>interval</em> specifies the number of weeks to skip. For example,
<codeclass="docutils literal notranslate"><spanclass="pre">interval=2</span></code> plots every second week.</p>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.DayLocator">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">DayLocator</code><spanclass="sig-paren">(</span><em>bymonthday=None</em>, <em>interval=1</em>, <em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#DayLocator"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.DayLocator" title="Permalink to this definition">¶</a></dt>
<p>Mark every second in <em>bysecond</em>; <em>bysecond</em> can be an int or
sequence. Default is to tick every second: <codeclass="docutils literal notranslate"><spanclass="pre">bysecond</span><spanclass="pre">=</span><spanclass="pre">range(60)</span></code></p>
<p><em>interval</em> is the interval between each iteration. For
example, if <codeclass="docutils literal notranslate"><spanclass="pre">interval=2</span></code>, mark every second occurrence.</p>
</dd></dl>
<dlclass="class">
<dtid="matplotlib.dates.MicrosecondLocator">
<emclass="property">class </em><codeclass="descclassname">matplotlib.dates.</code><codeclass="descname">MicrosecondLocator</code><spanclass="sig-paren">(</span><em>interval=1</em>, <em>tz=None</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#MicrosecondLocator"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.MicrosecondLocator" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_axis</code><spanclass="sig-paren">(</span><em>self</em>, <em>axis</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#MicrosecondLocator.set_axis"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.MicrosecondLocator.set_axis" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_data_interval</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#MicrosecondLocator.set_data_interval"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.MicrosecondLocator.set_data_interval" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">set_view_interval</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#MicrosecondLocator.set_view_interval"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.MicrosecondLocator.set_view_interval" title="Permalink to this definition">¶</a></dt>
<codeclass="descname">tick_values</code><spanclass="sig-paren">(</span><em>self</em>, <em>vmin</em>, <em>vmax</em><spanclass="sig-paren">)</span><aclass="reference internal" href="../_modules/matplotlib/dates.html#MicrosecondLocator.tick_values"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink" href="#matplotlib.dates.MicrosecondLocator.tick_values" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the values of the located ticks given <strong>vmin</strong> and <strong>vmax</strong>.</p>
<divclass="admonition note">
<pclass="first admonition-title">Note</p>
<p>To get tick locations with the vmin and vmax values defined
automatically for the associated <codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">axis</span></code> simply call