Skip to content

Commit ee6a42f

Browse files
authored
Merge pull request matplotlib#18346 from timhoffm/plot_date
Soft-deprecate Axes.plot_date()
2 parents b46e503 + ef001b2 commit ee6a42f

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
``plot_date``
2+
~~~~~~~~~~~~~
3+
The use of `~.Axes.plot_date` is discouraged. This method exists for historic
4+
reasons and may be deprecated in the future.
5+
6+
- ``datetime``-like data should directly be plotted using `~.Axes.plot`.
7+
- If you need to plot plain numeric data as :ref:`date-format` or
8+
need to set a timezone, call ``ax.xaxis.axis_date`` / ``ax.yaxis.axis_date``
9+
before `~.Axes.plot`. See `.Axis.axis_date`.

examples/ticks_and_spines/date_demo_convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
y = np.arange(len(dates))
1818

1919
fig, ax = plt.subplots()
20-
ax.plot_date(dates, y ** 2)
20+
ax.plot(dates, y**2, 'o')
2121

2222
# this is superfluous, since the autoscaler should get it right, but
2323
# use date2num and num2date to convert between dates and floats if

examples/ticks_and_spines/date_demo_rrule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
fig, ax = plt.subplots()
38-
plt.plot_date(dates, s)
38+
plt.plot(dates, s, 'o')
3939
ax.xaxis.set_major_locator(loc)
4040
ax.xaxis.set_major_formatter(formatter)
4141
ax.xaxis.set_tick_params(rotation=30, labelsize=10)

lib/matplotlib/axes/_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,18 @@ def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
16161616
"""
16171617
Plot co-ercing the axis to treat floats as dates.
16181618
1619+
.. admonition:: Discouraged
1620+
1621+
This method exists for historic reasons and will be deprecated in
1622+
the future.
1623+
1624+
- ``datetime``-like data should directly be plotted using
1625+
`~.Axes.plot`.
1626+
- If you need to plot plain numeric data as :ref:`date-format` or
1627+
need to set a timezone, call ``ax.xaxis.axis_date`` /
1628+
``ax.yaxis.axis_date`` before `~.Axes.plot`. See
1629+
`.Axis.axis_date`.
1630+
16191631
Similar to `.plot`, this plots *y* vs. *x* as lines or markers.
16201632
However, the axis labels are formatted as dates depending on *xdate*
16211633
and *ydate*. Note that `.plot` will work with `datetime` and

lib/matplotlib/dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
All the Matplotlib date converters, tickers and formatters are timezone aware.
8686
If no explicit timezone is provided, :rc:`timezone` is assumed. If you want to
8787
use a custom time zone, pass a `datetime.tzinfo` instance with the tz keyword
88-
argument to `num2date`, `~.Axes.plot_date`, and any custom date tickers or
88+
argument to `num2date`, `.Axis.axis_date`, and any custom date tickers or
8989
locators you create.
9090
9191
A wide range of specific and general purpose date tick locators and

0 commit comments

Comments
 (0)