Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Description
Bug report
Bug summary
This may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use thedata argument toscatter to plot a pandas dataframeTimestamp column.
Code for reproduction
Consider the following data
import matplotlib.pyplot as pltimport pandas as pdimport numpy as np; np.random.seed(42)df = pd.DataFrame(np.random.rand(10,2), columns=["x","y"])df["time"] = pd.date_range("2018-01-01", periods=10, freq="D")Using thedata argument, you may plot
plt.plot("x", "y", data=df)You may equally plot
plt.plot("time", "y", data=df)You may also scatter
plt.scatter(x="x", y="y", data=df)However, you may not scatter the timestamps
plt.scatter(x="time", y="y", data=df)This fails with aTypeError: invalid type promotion
Traceback (most recent call last): File "D:/.../test/GI_scatterdataarg.py", line 40, in <module> plt.scatter(x="time", y="y", data=df) File "d:\...\matplotlib\lib\matplotlib\pyplot.py", line 2623, in scatter verts=verts, edgecolors=edgecolors, data=data, **kwargs) File "d:\...\matplotlib\lib\matplotlib\__init__.py", line 1775, in inner return func(ax, *args, **kwargs) File "d:\...\matplotlib\lib\matplotlib\axes\_axes.py", line 3982, in scatter offsets = np.column_stack([x, y]) File "D:\...\matplotlib\lib\site-packages\numpy\lib\shape_base.py", line 369, in column_stack return _nx.concatenate(arrays, 1)TypeError: invalid type promotionThis is a bit surprising since you may well plot timestamps through scatter
plt.scatter(x=df.time.values, y=df.x.values)just not through thedata argument.
Expected outcome
Given that one may plot the timestamps correctly withplot and timestamps withscatter by providing the values, it would be nice to be able to use thedata argument withscatter as well.
... and ideally withbar,fill_between etc. ;-)
Matplotlib version
- Operating system: Win 8.1
- Matplotlib version: master 2.2.2.post1270+g6665bc739
- Matplotlib backend: Qt5Agg
- Python version: 3.6
- Jupyter version (if applicable):
- Other libraries: Pandas 0.22.0