Skip to content

Commit 1db6604

Browse files
committed
improve docstring of Axes.plot_date and parts of matplotlib.dates
1 parent f5fb78a commit 1db6604

File tree

2 files changed

+58
-43
lines changed

2 files changed

+58
-43
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,64 +1381,66 @@ def plot(self, *args, **kwargs):
13811381
def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
13821382
**kwargs):
13831383
"""
1384-
A plot with data that contains dates.
1385-
1386-
Similar to the :func:`~matplotlib.pyplot.plot` command, except
1387-
the *x* or *y* (or both) data is considered to be dates, and the
1388-
axis is labeled accordingly.
1389-
1390-
*x* and/or *y* can be a sequence of dates represented as float
1391-
days since 0001-01-01 UTC.
1392-
1393-
Note if you are using custom date tickers and formatters, it
1394-
may be necessary to set the formatters/locators after the call
1395-
to :meth:`plot_date` since :meth:`plot_date` will set the
1396-
default tick locator to
1397-
:class:`matplotlib.dates.AutoDateLocator` (if the tick
1398-
locator is not already set to a
1399-
:class:`matplotlib.dates.DateLocator` instance) and the
1400-
default tick formatter to
1401-
:class:`matplotlib.dates.AutoDateFormatter` (if the tick
1402-
formatter is not already set to a
1403-
:class:`matplotlib.dates.DateFormatter` instance).
1384+
Plot data that contains dates.
14041385
1386+
Similar to `.plot`, this plots *y* vs. *x* as lines or markers.
1387+
However, the axis labels are formatted as dates depending on *xdate*
1388+
and *ydate*.
14051389
14061390
Parameters
14071391
----------
1408-
fmt : string
1409-
The plot format string.
1392+
x, y : array-like
1393+
The coordinates of the data points. If *xdate* or *ydate* is
1394+
*True*, the respective values *x* or *y* are interpreted as
1395+
:ref:`Matplotlib dates <date-format>`.
1396+
1397+
fmt : str, optional
1398+
The plot format string. For details, see the corresponding
1399+
parameter in `.plot`.
14101400
14111401
tz : [ *None* | timezone string | :class:`tzinfo` instance]
1412-
The time zone to use in labeling dates. If *None*, defaults to rc
1413-
value.
1402+
The time zone to use in labeling dates. If *None*, defaults to
1403+
rcParam ``timezone``.
14141404
1415-
xdate : boolean
1416-
If *True*, the *x*-axis will be labeled with dates.
1405+
xdate : bool, optional, default: True
1406+
If *True*, the *x*-axis will be interpreted as Matplotlib dates.
14171407
1418-
ydate : boolean
1419-
If *True*, the *y*-axis will be labeled with dates.
1408+
ydate : bool, optional, default: False
1409+
If *True*, the *y*-axis will be interpreted as Matplotlib dates.
14201410
14211411
14221412
Returns
14231413
-------
14241414
lines
1415+
A list of `.Line2D` objects that were added to the axes.
14251416
14261417
1427-
See Also
1428-
--------
1429-
matplotlib.dates : helper functions on dates
1430-
matplotlib.dates.date2num : how to convert dates to num
1431-
matplotlib.dates.num2date : how to convert num to dates
1432-
matplotlib.dates.drange : how floating point dates
1433-
14341418
Other Parameters
14351419
----------------
1436-
**kwargs :
1420+
**kwargs
14371421
Keyword arguments control the :class:`~matplotlib.lines.Line2D`
14381422
properties:
14391423
14401424
%(Line2D)s
14411425
1426+
1427+
See Also
1428+
--------
1429+
matplotlib.dates : Helper functions on dates.
1430+
matplotlib.dates.date2num : Convert dates to num.
1431+
matplotlib.dates.num2date : Convert num to dates.
1432+
matplotlib.dates.drange : Create an equally spaced sequence of dates.
1433+
1434+
1435+
Notes
1436+
-----
1437+
If you are using custom date tickers and formatters, it may be
1438+
necessary to set the formatters/locators after the call to
1439+
`.plot_date`. `.plot_date` will set the default tick locator to
1440+
`.AutoDateLocator` (if the tick locator is not already set to a
1441+
`.DateLocator` instance) and the default tick formatter to
1442+
`.AutoDateFormatter` (if the tick formatter is not already set to a
1443+
`.DateFormatter` instance).
14421444
"""
14431445

14441446
if not self._hold:

lib/matplotlib/dates.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,29 @@
44
:mod:`dateutil`.
55
66
7-
.. date-format:
7+
.. _date-format:
88
99
Matplotlib date format
1010
----------------------
1111
Matplotlib represents dates using floating point numbers specifying the number
1212
of days since 0001-01-01 UTC, plus 1. For example, 0001-01-01, 06:00 is 1.25,
1313
not 0.25. Values < 1, i.e. dates before 0001-01-01 UTC are not supported.
1414
15-
The helper functions :func:`date2num`, :func:`num2date` and :func:`drange` are
16-
used for easy conversion between :mod:`datetime` objects and Matplotlib dates.
15+
There are a number of helper functions to convert between :mod:`datetime`
16+
objects and Matplotlib dates:
17+
18+
.. currentmodule:: matplotlib.dates
19+
20+
.. autosummary::
21+
:nosignatures:
22+
23+
date2num
24+
num2date
25+
num2timedelta
26+
epoch2num
27+
num2epoch
28+
mx2num
29+
drange
1730
1831
.. note::
1932
@@ -28,7 +41,7 @@
2841
732403, whereas using the Gregorian calendar via the datetime
2942
module we find::
3043
31-
In [1]: date(2006,4,1).toordinal() - date(1,1,1).toordinal()
44+
In [1]: date(2006, 4, 1).toordinal() - date(1, 1, 1).toordinal()
3245
Out[1]: 732401
3346
3447
All the Matplotlib date converters, tickers and formatters are timezone aware.
@@ -467,9 +480,9 @@ def _ordinalf_to_timedelta(x):
467480

468481
def num2timedelta(x):
469482
"""
470-
Convert number of days to a :class:`timdelta` object.
483+
Convert number of days to a `~datetime.timedelta` object.
471484
472-
If *x* is a sequence, a sequence of :class:`timedelta` objects will
485+
If *x* is a sequence, a sequence of `~datetime.timedelta` objects will
473486
be returned.
474487
475488
Parameters
@@ -479,7 +492,7 @@ def num2timedelta(x):
479492
480493
Returns
481494
-------
482-
`.timedelta` or list[:class:`.timedelta`]
495+
`datetime.timedelta` or list[`datetime.timedelta`]
483496
484497
"""
485498
if not cbook.iterable(x):

0 commit comments

Comments
 (0)