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 the data argument to scatter to plot a pandas dataframe Timestamp column.
Code for reproduction
Consider the following data
import matplotlib.pyplot as plt
import pandas as pd
import 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 the data 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 a TypeError: 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 promotion
This 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 the data argument.
Expected outcome
Given that one may plot the timestamps correctly with plot and timestamps with scatter by providing the values, it would be nice to be able to use the data argument with scatter as well.
... and ideally with bar, 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
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 the
dataargument toscatterto plot a pandas dataframeTimestampcolumn.Code for reproduction
Consider the following data
Using the
dataargument, you may plotYou may equally plot
You may also scatter
However, you may not scatter the timestamps
This fails with a
TypeError: invalid type promotionThis is a bit surprising since you may well plot timestamps through scatter
just not through the
dataargument.Expected outcome
Given that one may plot the timestamps correctly with
plotand timestamps withscatterby providing the values, it would be nice to be able to use thedataargument withscatteras well.... and ideally with
bar,fill_betweenetc. ;-)Matplotlib version