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

Skip to content

Commit 4545764

Browse files
committed
Add pending deprecation to plot_date()
1 parent d86112a commit 4545764

File tree

3 files changed

+28
-9
lines changed

3 files changed

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

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1609,14 +1609,16 @@ def plot(self, *args, scalex=True, scaley=True, data=None, **kwargs):
16091609
self._request_autoscale_view(scalex=scalex, scaley=scaley)
16101610
return lines
16111611

1612+
@cbook.deprecated("3.4", pending=True,
1613+
alternative="plot() and if needed Axis.axis_date()")
16121614
@_preprocess_data(replace_names=["x", "y"], label_namer="y")
16131615
@docstring.dedent_interpd
16141616
def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
16151617
**kwargs):
16161618
"""
16171619
Plot co-ercing the axis to treat floats as dates.
16181620
1619-
.. note::
1621+
.. admonition:: Discouraged
16201622
16211623
This method exists for historic reasons and will be deprecated in
16221624
the future.

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ def test_single_date():
670670
data1 = [-65.54]
671671

672672
fig, ax = plt.subplots(2, 1)
673-
ax[0].plot_date(time1 + dt, data1, 'o', color='r')
673+
with pytest.warns(PendingDeprecationWarning):
674+
ax[0].plot_date(time1 + dt, data1, 'o', color='r')
674675
ax[1].plot(time1, data1, 'o', color='r')
675676

676677

@@ -5830,11 +5831,13 @@ def test_date_timezone_x():
58305831
# Same Timezone
58315832
plt.figure(figsize=(20, 12))
58325833
plt.subplot(2, 1, 1)
5833-
plt.plot_date(time_index, [3] * 3, tz='Canada/Eastern')
5834+
with pytest.warns(PendingDeprecationWarning):
5835+
plt.plot_date(time_index, [3] * 3, tz='Canada/Eastern')
58345836

58355837
# Different Timezone
58365838
plt.subplot(2, 1, 2)
5837-
plt.plot_date(time_index, [3] * 3, tz='UTC')
5839+
with pytest.warns(PendingDeprecationWarning):
5840+
plt.plot_date(time_index, [3] * 3, tz='UTC')
58385841

58395842

58405843
@image_comparison(['date_timezone_y.png'])
@@ -5847,12 +5850,14 @@ def test_date_timezone_y():
58475850
# Same Timezone
58485851
plt.figure(figsize=(20, 12))
58495852
plt.subplot(2, 1, 1)
5850-
plt.plot_date([3] * 3,
5851-
time_index, tz='Canada/Eastern', xdate=False, ydate=True)
5853+
with pytest.warns(PendingDeprecationWarning):
5854+
plt.plot_date([3] * 3,
5855+
time_index, tz='Canada/Eastern', xdate=False, ydate=True)
58525856

58535857
# Different Timezone
58545858
plt.subplot(2, 1, 2)
5855-
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)
5859+
with pytest.warns(PendingDeprecationWarning):
5860+
plt.plot_date([3] * 3, time_index, tz='UTC', xdate=False, ydate=True)
58565861

58575862

58585863
@image_comparison(['date_timezone_x_and_y.png'], tol=1.0)
@@ -5865,11 +5870,13 @@ def test_date_timezone_x_and_y():
58655870
# Same Timezone
58665871
plt.figure(figsize=(20, 12))
58675872
plt.subplot(2, 1, 1)
5868-
plt.plot_date(time_index, time_index, tz='UTC', ydate=True)
5873+
with pytest.warns(PendingDeprecationWarning):
5874+
plt.plot_date(time_index, time_index, tz='UTC', ydate=True)
58695875

58705876
# Different Timezone
58715877
plt.subplot(2, 1, 2)
5872-
plt.plot_date(time_index, time_index, tz='US/Eastern', ydate=True)
5878+
with pytest.warns(PendingDeprecationWarning):
5879+
plt.plot_date(time_index, time_index, tz='US/Eastern', ydate=True)
58735880

58745881

58755882
@image_comparison(['axisbelow.png'], remove_text=True)

0 commit comments

Comments
 (0)