diff --git a/doc/api/next_api_changes/deprecations/23081-OG.rst b/doc/api/next_api_changes/deprecations/23081-OG.rst new file mode 100644 index 000000000000..da7f697023c0 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/23081-OG.rst @@ -0,0 +1,8 @@ +``date_ticker_factory`` deprecated +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The ``date_ticker_factory`` method in the `matplotlib.dates` module is +deprecated. Instead use `~.AutoDateLocator` and `~.AutoDateFormatter` for a +more flexible and scalable locator and formatter. + +If you need the exact ``date_ticker_factory`` behavior, please copy the code. diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 30b2f40466f0..1eb73dbef4fe 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1782,6 +1782,8 @@ def num2epoch(d): return np.asarray(d) * SEC_PER_DAY - dt +@_api.deprecated("3.6", alternative="`AutoDateLocator` and `AutoDateFormatter`" + " or vendor the code") def date_ticker_factory(span, tz=None, numticks=5): """ Create a date locator with *numticks* (approx) and a date formatter diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 5258da36a7e7..604a40689fdf 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -1319,8 +1319,9 @@ def test_concise_formatter_call(): (200, mdates.MonthLocator), (2000, mdates.YearLocator))) def test_date_ticker_factory(span, expected_locator): - locator, _ = mdates.date_ticker_factory(span) - assert isinstance(locator, expected_locator) + with pytest.warns(_api.MatplotlibDeprecationWarning): + locator, _ = mdates.date_ticker_factory(span) + assert isinstance(locator, expected_locator) def test_usetex_newline():