Closed
Description
Bug report
Bug summary
matplotlib.pyplot.bar
unable to use pandas.core.indexes.datetimes.DatetimeIndex
as x
Code for reproduction
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas_datareader.data as web
style.use('ggplot')
start = dt.datetime(2017,10,1)
end = dt.datetime(2017,10,28)
df = web.DataReader('AAPL', 'yahoo', start, end)
ax1 = plt.subplot2grid((6,1), (0,0), rowspan=5, colspan=1)
ax2 = plt.subplot2grid((6,1), (5,0), rowspan=1, colspan=1, sharex=ax1)
ax1.plot(df.index, df['Adj Close'])
ax2.bar(df.index, df['Volume'])
plt.show()
Output
Traceback (most recent call last):
File "C:/Users/x/x/x/test.py", line 13, in <module>
ax2.bar(df.index, df['Volume'])
File "C:\Users\Johnson\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\__init__.py", line 1710, in inner
return func(ax, *args, **kwargs)
File "C:\Users\Johnson\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 2129, in bar
left = x - width / 2
TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('float64')
Matplotlib version
- Operating system: Windows 10 (15063.540)
- Matplotlib (retrieved from pip) version: 2.1.0
- Matplotlib backend (
print(matplotlib.get_backend())
): TkAgg - Python version: 3.6.2
- Other libraries: numpy 1.13.3, pandas 0.21.0, pandas-datareader=0.5.0