diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 61119089fdb42..ceb03ce06a0ec 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -629,8 +629,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` (:issue:`22039`) Groupby/Resample/Rolling ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/plotting/_converter.py b/pandas/plotting/_converter.py index 3bb0b98851234..96ea8a542a451 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