From ee10beefc97545ddc291a88c67ab6ca39c7cda51 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Tue, 24 Jul 2018 10:15:38 -0500 Subject: [PATCH 1/2] BUG: Matplotlib scatter datetime --- doc/source/whatsnew/v0.24.0.txt | 4 ++-- pandas/plotting/_converter.py | 6 +++++- pandas/tests/plotting/test_datetimelike.py | 11 +++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 137fd5aafe5bd..e399f32b13531 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -527,8 +527,8 @@ I/O Plotting ^^^^^^^^ -- Bug in :func:'DataFrame.plot.scatter' and :func:'DataFrame.plot.hexbin' caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`) -- +- Bug in :func:`DataFrame.plot.scatter` and :func:`DataFrame.plot.hexbin` caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`) +- Bug in plotting a Series with datetimes using :func:`matplotlib.axes.Axes.scatter`. Groupby/Resample/Rolling ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/plotting/_converter.py b/pandas/plotting/_converter.py index beebf84b8a033..cc835cd9563ae 100644 --- a/pandas/plotting/_converter.py +++ b/pandas/plotting/_converter.py @@ -320,7 +320,11 @@ def try_parse(values): return values elif isinstance(values, compat.string_types): return try_parse(values) - elif isinstance(values, (list, tuple, np.ndarray, Index)): + elif isinstance(values, (list, tuple, np.ndarray, Index, ABCSeries)): + if isinstance(values, ABCSeries): + # https://github.com/matplotlib/matplotlib/issues/11391 + # Series was skipped. Convert to DatetimeIndex to get asi8 + values = Index(values) if isinstance(values, Index): values = values.values if not isinstance(values, np.ndarray): diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index e3d502cd373e4..0abe82d138e5e 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1483,6 +1483,17 @@ def test_add_matplotlib_datetime64(self): l1, l2 = ax.lines tm.assert_numpy_array_equal(l1.get_xydata(), l2.get_xydata()) + def test_matplotlib_scatter_datetime64(self): + # https://github.com/matplotlib/matplotlib/issues/11391 + df = DataFrame(np.random.RandomState(0).rand(10, 2), + columns=["x", "y"]) + df["time"] = date_range("2018-01-01", periods=10, freq="D") + fig, ax = self.plt.subplots() + ax.scatter(x="time", y="y", data=df) + fig.canvas.draw() + label = ax.get_xticklabels()[0] + assert label.get_text() == '2017-12-12' + def _check_plot_works(f, freq=None, series=None, *args, **kwargs): import matplotlib.pyplot as plt From 0132feaae9bb85590380f23dc090d996f6667d9d Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Thu, 2 Aug 2018 06:39:12 -0400 Subject: [PATCH 2/2] update whatsnew --- doc/source/whatsnew/v0.24.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 8f1a6539eefd2..ceb03ce06a0ec 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -630,7 +630,7 @@ Plotting ^^^^^^^^ - Bug in :func:`DataFrame.plot.scatter` and :func:`DataFrame.plot.hexbin` caused x-axis label and ticklabels to disappear when colorbar was on in IPython inline backend (:issue:`10611`, :issue:`10678`, and :issue:`20455`) -- Bug in plotting a Series with datetimes using :func:`matplotlib.axes.Axes.scatter`. +- Bug in plotting a Series with datetimes using :func:`matplotlib.axes.Axes.scatter` (:issue:`22039`) Groupby/Resample/Rolling ^^^^^^^^^^^^^^^^^^^^^^^^