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

Skip to content

Commit 855e3bb

Browse files
authored
Merge pull request #18429 from jklymak/doc-fix-date-example
DOC: fix date example
2 parents e26d497 + 8929644 commit 855e3bb

File tree

1 file changed

+16
-10
lines changed
  • examples/text_labels_and_annotations

1 file changed

+16
-10
lines changed

examples/text_labels_and_annotations/date.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@
77
formatters. See :doc:`/gallery/ticks_and_spines/major_minor_demo` for more
88
information on controlling major and minor ticks.
99
10-
All Matplotlib date plotting is done by converting date instances into
11-
days since 0001-01-01 00:00:00 UTC plus one day (for historical reasons).
12-
The conversion, tick locating and formatting is done behind the scenes
13-
so this is most transparent to you. The :mod:`matplotlib.dates` module
14-
provides the converter functions `.date2num` and `.num2date`, which convert
15-
`datetime.datetime` and `numpy.datetime64` objects to and from Matplotlib's
16-
internal representation.
17-
18-
An alternative way of displaying dates can be seen at
19-
:doc:`/gallery/ticks_and_spines/date_concise_formatter`.
10+
Matplotlib date plotting is done by converting date instances into
11+
days since an epoch (by default 1970-01-01T00:00:00). The
12+
:mod:`matplotlib.dates` module provides the converter functions `.date2num`
13+
and `.num2date`, which convert `datetime.datetime` and `numpy.datetime64`
14+
objects to and from Matplotlib's internal representation. These data
15+
types are registered with with the unit conversion mechanism described in
16+
:mod:`matplotlib.units`, so the conversion happens automatically for the user.
17+
The registration process also sets the default tick ``locator`` and
18+
``formatter`` for the axis to be `~.matplotlib.dates.AutoDateLocator` and
19+
`~.matplotlib.dates.AutoDateFormatter`. These can be changed manually with
20+
`.Axis.set_major_locator` and `.Axis.set_major_formatter`; see for example
21+
:doc:`/gallery/ticks_and_spines/date_demo_convert`.
22+
23+
An alternative formatter is the `~.matplotlib.dates.ConciseDateFormatter`
24+
as described at :doc:`/gallery/ticks_and_spines/date_concise_formatter`,
25+
which often removes the need to rotate the tick labels.
2026
"""
2127

2228
import numpy as np

0 commit comments

Comments
 (0)