diff --git a/doc/api/axes_api.rst b/doc/api/axes_api.rst index 6fd05a604347..6b8503a24b1f 100644 --- a/doc/api/axes_api.rst +++ b/doc/api/axes_api.rst @@ -54,7 +54,6 @@ Basic Axes.errorbar Axes.scatter - Axes.plot_date Axes.step Axes.loglog diff --git a/doc/api/next_api_changes/removals/29697-REC.rst b/doc/api/next_api_changes/removals/29697-REC.rst new file mode 100644 index 000000000000..0155578f0c21 --- /dev/null +++ b/doc/api/next_api_changes/removals/29697-REC.rst @@ -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`. diff --git a/doc/api/prev_api_changes/api_changes_1.4.x.rst b/doc/api/prev_api_changes/api_changes_1.4.x.rst index 30f077995e44..915aa28a9f26 100644 --- a/doc/api/prev_api_changes/api_changes_1.4.x.rst +++ b/doc/api/prev_api_changes/api_changes_1.4.x.rst @@ -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 diff --git a/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst b/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst index d10da55a97f8..05f42035f1ac 100644 --- a/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst +++ b/doc/api/prev_api_changes/api_changes_3.5.0/deprecations.rst @@ -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`. diff --git a/doc/api/prev_api_changes/api_changes_3.9.0/deprecations.rst b/doc/api/prev_api_changes/api_changes_3.9.0/deprecations.rst index 00469459d20a..2cf1df8c9579 100644 --- a/doc/api/prev_api_changes/api_changes_3.9.0/deprecations.rst +++ b/doc/api/prev_api_changes/api_changes_3.9.0/deprecations.rst @@ -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`. diff --git a/doc/api/pyplot_summary.rst b/doc/api/pyplot_summary.rst index d0def34c4995..cdd57bfe6276 100644 --- a/doc/api/pyplot_summary.rst +++ b/doc/api/pyplot_summary.rst @@ -51,7 +51,6 @@ Basic plot errorbar scatter - plot_date step loglog semilogx diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 8310c57cebba..74fc3f4c5a14 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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 `. - - 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): diff --git a/lib/matplotlib/axes/_axes.pyi b/lib/matplotlib/axes/_axes.pyi index c780fe012fa0..e644860f8b1b 100644 --- a/lib/matplotlib/axes/_axes.pyi +++ b/lib/matplotlib/axes/_axes.pyi @@ -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]: ... diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 45d46238bc96..ab33146d2185 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -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 @@ -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( diff --git a/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_x.png b/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_x.png deleted file mode 100644 index b193acac1bab..000000000000 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_x.png and /dev/null differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_x_and_y.png b/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_x_and_y.png deleted file mode 100644 index d39489636a7b..000000000000 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_x_and_y.png and /dev/null differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_y.png b/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_y.png deleted file mode 100644 index e6b1b9ae0e95..000000000000 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/date_timezone_y.png and /dev/null differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/single_date.png b/lib/matplotlib/tests/baseline_images/test_axes/single_date.png deleted file mode 100644 index 9df3334340c2..000000000000 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/single_date.png and /dev/null differ diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 0025781d4901..0a5a5ff23e80 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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)) @@ -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. diff --git a/lib/matplotlib/tests/test_datetime.py b/lib/matplotlib/tests/test_datetime.py index 276056d044ae..821552befcf0 100644 --- a/lib/matplotlib/tests/test_datetime.py +++ b/lib/matplotlib/tests/test_datetime.py @@ -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): diff --git a/lib/matplotlib/tests/test_pyplot.py b/lib/matplotlib/tests/test_pyplot.py index 51bad715537a..ab713707bace 100644 --- a/lib/matplotlib/tests/test_pyplot.py +++ b/lib/matplotlib/tests/test_pyplot.py @@ -381,7 +381,7 @@ def extract_documented_functions(lines): :nosignatures: plot - plot_date + errorbar """ functions = [] diff --git a/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py b/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py index b045e8dc8756..a278b27ed63a 100644 --- a/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py @@ -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" diff --git a/tools/boilerplate.py b/tools/boilerplate.py index 962ae899c458..7055fa4077f9 100644 --- a/tools/boilerplate.py +++ b/tools/boilerplate.py @@ -256,7 +256,6 @@ def boilerplate_gen(): 'phase_spectrum', 'pie', 'plot', - 'plot_date', 'psd', 'quiver', 'quiverkey',