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

Skip to content

MNT: remove plot_date #29697

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 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion doc/api/axes_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Basic
Axes.errorbar
Axes.scatter

Axes.plot_date
Axes.step

Axes.loglog
Expand Down
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/removals/29697-REC.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
``plot_date``
~~~~~~~~~~~~~

Use of ``plot_date`` has been discouraged since Matplotlib 3.5 and deprecated
since 3.9. The ``plot_date`` function has now been removed.

- ``datetime``-like data should directly be plotted using `~.Axes.plot`.
- If you need to plot plain numeric data as :ref:`date-format` or need to set
a timezone, call ``ax.xaxis.axis_date`` / ``ax.yaxis.axis_date`` before
`~.Axes.plot`. See `.Axis.axis_date`.
2 changes: 1 addition & 1 deletion doc/api/prev_api_changes/api_changes_1.4.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Code changes
``matplotlib.testing.image_util.autocontrast``. These will be removed
completely in v1.5.0.

* The ``fmt`` argument of :meth:`~matplotlib.axes.Axes.plot_date` has been
* The ``fmt`` argument of ``Axes.plot_date`` has been
changed from ``bo`` to just ``o``, so color cycling can happen by default.

* Removed the class ``FigureManagerQTAgg`` and deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type. See their documentation for the types they expect.
Discouraged: ``plot_date``
~~~~~~~~~~~~~~~~~~~~~~~~~~

The use of `~.Axes.plot_date` is discouraged. This method exists for historic
The use of ``plot_date`` is discouraged. This method exists for historic
reasons and may be deprecated in the future.

- ``datetime``-like data should directly be plotted using `~.Axes.plot`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Deprecations
``plot_date``
^^^^^^^^^^^^^

Use of `~.Axes.plot_date` has been discouraged since Matplotlib 3.5 and the function is
Use of ``plot_date`` has been discouraged since Matplotlib 3.5 and the function is
now formally deprecated.

- ``datetime``-like data should directly be plotted using `~.Axes.plot`.
Expand Down
1 change: 0 additions & 1 deletion doc/api/pyplot_summary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ Basic
plot
errorbar
scatter
plot_date
step
loglog
semilogx
Expand Down
81 changes: 0 additions & 81 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,87 +1778,6 @@ def plot(self, *args, scalex=True, scaley=True, data=None, **kwargs):
self._request_autoscale_view("y")
return lines

@_api.deprecated("3.9", alternative="plot")
@_preprocess_data(replace_names=["x", "y"], label_namer="y")
@_docstring.interpd
def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
**kwargs):
"""
Plot coercing the axis to treat floats as dates.

.. deprecated:: 3.9

This method exists for historic reasons and will be removed in version 3.11.

- ``datetime``-like data should directly be plotted using
`~.Axes.plot`.
- If you need to plot plain numeric data as :ref:`date-format` or
need to set a timezone, call ``ax.xaxis.axis_date`` /
``ax.yaxis.axis_date`` before `~.Axes.plot`. See
`.Axis.axis_date`.

Similar to `.plot`, this plots *y* vs. *x* as lines or markers.
However, the axis labels are formatted as dates depending on *xdate*
and *ydate*. Note that `.plot` will work with `datetime` and
`numpy.datetime64` objects without resorting to this method.

Parameters
----------
x, y : array-like
The coordinates of the data points. If *xdate* or *ydate* is
*True*, the respective values *x* or *y* are interpreted as
:ref:`Matplotlib dates <date-format>`.

fmt : str, optional
The plot format string. For details, see the corresponding
parameter in `.plot`.

tz : timezone string or `datetime.tzinfo`, default: :rc:`timezone`
The time zone to use in labeling dates.

xdate : bool, default: True
If *True*, the *x*-axis will be interpreted as Matplotlib dates.

ydate : bool, default: False
If *True*, the *y*-axis will be interpreted as Matplotlib dates.

Returns
-------
list of `.Line2D`
Objects representing the plotted data.

Other Parameters
----------------
data : indexable object, optional
DATA_PARAMETER_PLACEHOLDER
**kwargs
Keyword arguments control the `.Line2D` properties:

%(Line2D:kwdoc)s

See Also
--------
matplotlib.dates : Helper functions on dates.
matplotlib.dates.date2num : Convert dates to num.
matplotlib.dates.num2date : Convert num to dates.
matplotlib.dates.drange : Create an equally spaced sequence of dates.

Notes
-----
If you are using custom date tickers and formatters, it may be
necessary to set the formatters/locators after the call to
`.plot_date`. `.plot_date` will set the default tick locator to
`.AutoDateLocator` (if the tick locator is not already set to a
`.DateLocator` instance) and the default tick formatter to
`.AutoDateFormatter` (if the tick formatter is not already set to a
`.DateFormatter` instance).
"""
if xdate:
self.xaxis_date(tz)
if ydate:
self.yaxis_date(tz)
return self.plot(x, y, fmt, **kwargs)

# @_preprocess_data() # let 'plot' do the unpacking..
@_docstring.interpd
def loglog(self, *args, **kwargs):
Expand Down
12 changes: 0 additions & 12 deletions lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,6 @@ class Axes(_AxesBase):
data=...,
**kwargs
) -> list[Line2D]: ...
def plot_date(
self,
x: ArrayLike,
y: ArrayLike,
fmt: str = ...,
tz: str | datetime.tzinfo | None = ...,
xdate: bool = ...,
ydate: bool = ...,
*,
data=...,
**kwargs
) -> list[Line2D]: ...
def loglog(self, *args, **kwargs) -> list[Line2D]: ...
def semilogx(self, *args, **kwargs) -> list[Line2D]: ...
def semilogy(self, *args, **kwargs) -> list[Line2D]: ...
Expand Down
26 changes: 0 additions & 26 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@

if TYPE_CHECKING:
from collections.abc import Callable, Hashable, Iterable, Sequence
import datetime
import pathlib
import os
from typing import Any, BinaryIO, Literal, TypeVar
Expand Down Expand Up @@ -3834,31 +3833,6 @@ def plot(
)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.plot_date)
def plot_date(
x: ArrayLike,
y: ArrayLike,
fmt: str = "o",
tz: str | datetime.tzinfo | None = None,
xdate: bool = True,
ydate: bool = False,
*,
data=None,
**kwargs,
) -> list[Line2D]:
return gca().plot_date(
x,
y,
fmt=fmt,
tz=tz,
xdate=xdate,
ydate=ydate,
**({"data": data} if data is not None else {}),
**kwargs,
)


# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
@_copy_docstring_and_deprecators(Axes.psd)
def psd(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
73 changes: 0 additions & 73 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,22 +895,6 @@ def test_single_point():
ax2.plot('b', 'b', 'o', data=data)


@image_comparison(['single_date.png'], style='mpl20')
def test_single_date():

# use former defaults to match existing baseline image
plt.rcParams['axes.formatter.limits'] = -7, 7
dt = mdates.date2num(np.datetime64('0000-12-31'))

time1 = [721964.0]
data1 = [-65.54]

fig, ax = plt.subplots(2, 1)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
ax[0].plot_date(time1 + dt, data1, 'o', color='r')
ax[1].plot(time1, data1, 'o', color='r')


@check_figures_equal(extensions=["png"])
def test_shaped_data(fig_test, fig_ref):
row = np.arange(10).reshape((1, -1))
Expand Down Expand Up @@ -7299,63 +7283,6 @@ def test_bar_uint8():
assert patch.xy[0] == x


@image_comparison(['date_timezone_x.png'], tol=1.0)
def test_date_timezone_x():
# Tests issue 5575
time_index = [datetime.datetime(2016, 2, 22, hour=x,
tzinfo=dateutil.tz.gettz('Canada/Eastern'))
for x in range(3)]

# Same Timezone
plt.figure(figsize=(20, 12))
plt.subplot(2, 1, 1)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
plt.plot_date(time_index, [3] * 3, tz='Canada/Eastern')

# Different Timezone
plt.subplot(2, 1, 2)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
plt.plot_date(time_index, [3] * 3, tz='UTC')


@image_comparison(['date_timezone_y.png'])
def test_date_timezone_y():
# Tests issue 5575
time_index = [datetime.datetime(2016, 2, 22, hour=x,
tzinfo=dateutil.tz.gettz('Canada/Eastern'))
for x in range(3)]

# Same Timezone
plt.figure(figsize=(20, 12))
plt.subplot(2, 1, 1)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
plt.plot_date([3] * 3, time_index, tz='Canada/Eastern', xdate=False, ydate=True)

# Different Timezone
plt.subplot(2, 1, 2)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)


@image_comparison(['date_timezone_x_and_y.png'], tol=1.0)
def test_date_timezone_x_and_y():
# Tests issue 5575
UTC = datetime.timezone.utc
time_index = [datetime.datetime(2016, 2, 22, hour=x, tzinfo=UTC)
for x in range(3)]

# Same Timezone
plt.figure(figsize=(20, 12))
plt.subplot(2, 1, 1)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
plt.plot_date(time_index, time_index, tz='UTC', ydate=True)

# Different Timezone
plt.subplot(2, 1, 2)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
plt.plot_date(time_index, time_index, tz='US/Eastern', ydate=True)


@image_comparison(['axisbelow.png'], remove_text=True)
def test_axisbelow():
# Test 'line' setting added in 6287.
Expand Down
20 changes: 0 additions & 20 deletions lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,26 +642,6 @@ def test_plot(self):
ax2.plot(range(1, N), x)
ax3.plot(x, x)

@mpl.style.context("default")
def test_plot_date(self):
mpl.rcParams["date.converter"] = "concise"
range_threshold = 10
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout="constrained")

x_dates = np.array(
[datetime.datetime(2023, 10, delta) for delta in range(1, range_threshold)]
)
y_dates = np.array(
[datetime.datetime(2023, 10, delta) for delta in range(1, range_threshold)]
)
x_ranges = np.array(range(1, range_threshold))
y_ranges = np.array(range(1, range_threshold))

with pytest.warns(mpl.MatplotlibDeprecationWarning):
ax1.plot_date(x_dates, y_dates)
ax2.plot_date(x_dates, y_ranges)
ax3.plot_date(x_ranges, y_dates)

@pytest.mark.xfail(reason="Test for quiver not written yet")
@mpl.style.context("default")
def test_quiver(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def extract_documented_functions(lines):
:nosignatures:

plot
plot_date
errorbar

"""
functions = []
Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def test_twin_axes_empty_and_removed():

def test_twin_axes_both_with_units():
host = host_subplot(111)
with pytest.warns(mpl.MatplotlibDeprecationWarning):
host.plot_date([0, 1, 2], [0, 1, 2], xdate=False, ydate=True)
host.yaxis.axis_date()
host.plot([0, 1, 2], [0, 1, 2])
twin = host.twinx()
twin.plot(["a", "b", "c"])
assert host.get_yticklabels()[0].get_text() == "00:00:00"
Expand Down
1 change: 0 additions & 1 deletion tools/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ def boilerplate_gen():
'phase_spectrum',
'pie',
'plot',
'plot_date',
'psd',
'quiver',
'quiverkey',
Expand Down
Loading