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

Skip to content

Commit ca5bb47

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

File tree

2 files changed

+59
-43
lines changed

2 files changed

+59
-43
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,64 +1535,67 @@ def plot(self, *args, **kwargs):
15351535
def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
15361536
**kwargs):
15371537
"""
1538-
A plot with data that contains dates.
1539-
1540-
Similar to the :func:`~matplotlib.pyplot.plot` command, except
1541-
the *x* or *y* (or both) data is considered to be dates, and the
1542-
axis is labeled accordingly.
1543-
1544-
*x* and/or *y* can be a sequence of dates represented as float
1545-
days since 0001-01-01 UTC.
1546-
1547-
Note if you are using custom date tickers and formatters, it
1548-
may be necessary to set the formatters/locators after the call
1549-
to :meth:`plot_date` since :meth:`plot_date` will set the
1550-
default tick locator to
1551-
:class:`matplotlib.dates.AutoDateLocator` (if the tick
1552-
locator is not already set to a
1553-
:class:`matplotlib.dates.DateLocator` instance) and the
1554-
default tick formatter to
1555-
:class:`matplotlib.dates.AutoDateFormatter` (if the tick
1556-
formatter is not already set to a
1557-
:class:`matplotlib.dates.DateFormatter` instance).
1538+
Plot data that contains dates.
15581539
1540+
Similar to `.plot`, this plots *y* vs. *x* as lines or markers.
1541+
However, the axis labels are formatted as dates depending on *xdate*
1542+
and *ydate*.
15591543
15601544
Parameters
15611545
----------
1562-
fmt : string
1563-
The plot format string.
1546+
x, y : array-like
1547+
The coordinates of the data points. If *xdate* or *ydate* is
1548+
*True*, the respective values *x* or *y* are interpreted as
1549+
:ref:`Matplotlib dates <date-format>`.
1550+
1551+
fmt : str, optional
1552+
The plot format string. For details, see the corresponding
1553+
parameter in `.plot`.
15641554
15651555
tz : [ *None* | timezone string | :class:`tzinfo` instance]
1566-
The time zone to use in labeling dates. If *None*, defaults to rc
1567-
value.
1556+
The time zone to use in labeling dates. If *None*, defaults to
1557+
rcParam ``timezone``.
15681558
1569-
xdate : boolean
1570-
If *True*, the *x*-axis will be labeled with dates.
1559+
xdate : bool, optional, default: True
1560+
If *True*, the *x*-axis will be interpreted as Matplotlib dates.
15711561
1572-
ydate : boolean
1573-
If *True*, the *y*-axis will be labeled with dates.
1562+
ydate : bool, optional, default: False
1563+
If *True*, the *y*-axis will be interpreted as Matplotlib dates.
15741564
15751565
15761566
Returns
15771567
-------
15781568
lines
1569+
A list of `.Line2D` objects that were added to the axes.
15791570
15801571
1581-
See Also
1582-
--------
1583-
matplotlib.dates : helper functions on dates
1584-
matplotlib.dates.date2num : how to convert dates to num
1585-
matplotlib.dates.num2date : how to convert num to dates
1586-
matplotlib.dates.drange : how floating point dates
1587-
15881572
Other Parameters
15891573
----------------
1590-
**kwargs :
1574+
**kwargs
15911575
Keyword arguments control the :class:`~matplotlib.lines.Line2D`
15921576
properties:
15931577
15941578
%(Line2D)s
15951579
1580+
1581+
See Also
1582+
--------
1583+
matplotlib.dates : Helper functions on dates.
1584+
matplotlib.dates.date2num : Convert dates to num.
1585+
matplotlib.dates.num2date : Convert num to dates.
1586+
matplotlib.dates.drange : Create an equally spaced sequence of dates.
1587+
1588+
1589+
Notes
1590+
-----
1591+
If you are using custom date tickers and formatters, it may be
1592+
necessary to set the formatters/locators after the call to
1593+
`.plot_date`. `.plot_date` will set the default tick locator to
1594+
`.AutoDateLocator` (if the tick locator is not already set to a
1595+
`.DateLocator` instance) and the default tick formatter to
1596+
`.AutoDateFormatter` (if the tick formatter is not already set to a
1597+
`.DateFormatter` instance).
1598+
15961599
"""
15971600

15981601
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.
@@ -502,9 +515,9 @@ def _ordinalf_to_timedelta(x):
502515

503516
def num2timedelta(x):
504517
"""
505-
Convert number of days to a :class:`timdelta` object.
518+
Convert number of days to a `~datetime.timedelta` object.
506519
507-
If *x* is a sequence, a sequence of :class:`timedelta` objects will
520+
If *x* is a sequence, a sequence of `~datetime.timedelta` objects will
508521
be returned.
509522
510523
Parameters
@@ -514,7 +527,7 @@ def num2timedelta(x):
514527
515528
Returns
516529
-------
517-
`.timedelta` or list[:class:`.timedelta`]
530+
`datetime.timedelta` or list[`datetime.timedelta`]
518531
519532
"""
520533
if not cbook.iterable(x):

0 commit comments

Comments
 (0)