FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cannot plot bar chart with DatetimeIndex · Issue #9613 · matplotlib/matplotlib · GitHub

Repository navigation

Cannot plot bar chart with DatetimeIndex #9613

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

Activity

  1. added this to the milestone on Oct 29, 2017
  2. tacaswell commented on Oct 29, 2017

    Member

    Something is not going correct with the unit handling (which in what converts from datetime objcets / np.datetime values -> floats that we can plot). It looks like only one or neither of the values an being converted here as we attempt to center the bars.

  3. QuLogic commented on Oct 29, 2017

    Member

    Same problem as #9610 perhaps?

  4. dstansby commented on Oct 30, 2017

    Member

    Yep, I'd guess it is the same root issue as #9610

  5. timhoffm commented on Mar 21, 2018

    Member

    Works here on 2.2.2. Probably fixed by #9779.

    Please reopen if there are still issues.

  6. modified the milestones: , v2.2.0 on Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL