Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: fix date example #18429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions examples/text_labels_and_annotations/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@
formatters. See :doc:`/gallery/ticks_and_spines/major_minor_demo` for more
information on controlling major and minor ticks.

All Matplotlib date plotting is done by converting date instances into
days since 0001-01-01 00:00:00 UTC plus one day (for historical reasons).
The conversion, tick locating and formatting is done behind the scenes
so this is most transparent to you. The :mod:`matplotlib.dates` module
provides the converter functions `.date2num` and `.num2date`, which convert
`datetime.datetime` and `numpy.datetime64` objects to and from Matplotlib's
internal representation.

An alternative way of displaying dates can be seen at
:doc:`/gallery/ticks_and_spines/date_concise_formatter`.
Matplotlib date plotting is done by converting date instances into
days since an epoch (by default 1970-01-01T00:00:00). The
:mod:`matplotlib.dates` module provides the converter functions `.date2num`
and `.num2date`, which convert `datetime.datetime` and `numpy.datetime64`
objects to and from Matplotlib's internal representation. These data
types are registered with with the unit conversion mechanism described in
:mod:`matplotlib.units`, so the conversion happens automatically for the user.
The registration process also sets the default tick ``locator`` and
``formatter`` for the axis to be `~.matplotlib.dates.AutoDateLocator` and
`~.matplotlib.dates.AutoDateFormatter`. These can be changed manually with
`.Axis.set_major_locator` and `.Axis.set_major_formatter`; see for example
:doc:`/gallery/ticks_and_spines/date_demo_convert`.

An alternative formatter is the `~.matplotlib.dates.ConciseDateFormatter`
as described at :doc:`/gallery/ticks_and_spines/date_concise_formatter`,
which often removes the need to rotate the tick labels.
"""

import numpy as np
Expand Down