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

Skip to content

Commit bcae8a7

Browse files
committed
Discourage use of plot_date()
1 parent d86112a commit bcae8a7

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
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`.

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ 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-
.. note::
1619+
.. admonition:: Discouraged
16201620
16211621
This method exists for historic reasons and will be deprecated in
16221622
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)