Skip to content

Commit dea38dd

Browse files
TomAugspurgerdberenbaum
authored andcommitted
BUG: Matplotlib scatter datetime (pandas-dev#22039)
1 parent 071c165 commit dea38dd

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

doc/source/whatsnew/v0.24.0.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ I/O
631631
Plotting
632632
^^^^^^^^
633633

634-
- 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`)
635-
-
634+
- 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`)
635+
- Bug in plotting a Series with datetimes using :func:`matplotlib.axes.Axes.scatter` (:issue:`22039`)
636636

637637
Groupby/Resample/Rolling
638638
^^^^^^^^^^^^^^^^^^^^^^^^

pandas/plotting/_converter.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,11 @@ def try_parse(values):
320320
return values
321321
elif isinstance(values, compat.string_types):
322322
return try_parse(values)
323-
elif isinstance(values, (list, tuple, np.ndarray, Index)):
323+
elif isinstance(values, (list, tuple, np.ndarray, Index, ABCSeries)):
324+
if isinstance(values, ABCSeries):
325+
# https://github.com/matplotlib/matplotlib/issues/11391
326+
# Series was skipped. Convert to DatetimeIndex to get asi8
327+
values = Index(values)
324328
if isinstance(values, Index):
325329
values = values.values
326330
if not isinstance(values, np.ndarray):

pandas/tests/plotting/test_datetimelike.py

+11
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,17 @@ def test_add_matplotlib_datetime64(self):
14831483
l1, l2 = ax.lines
14841484
tm.assert_numpy_array_equal(l1.get_xydata(), l2.get_xydata())
14851485

1486+
def test_matplotlib_scatter_datetime64(self):
1487+
# https://github.com/matplotlib/matplotlib/issues/11391
1488+
df = DataFrame(np.random.RandomState(0).rand(10, 2),
1489+
columns=["x", "y"])
1490+
df["time"] = date_range("2018-01-01", periods=10, freq="D")
1491+
fig, ax = self.plt.subplots()
1492+
ax.scatter(x="time", y="y", data=df)
1493+
fig.canvas.draw()
1494+
label = ax.get_xticklabels()[0]
1495+
assert label.get_text() == '2017-12-12'
1496+
14861497

14871498
def _check_plot_works(f, freq=None, series=None, *args, **kwargs):
14881499
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)