8000 ax.bar throws when x axis is pandas datetime · Issue #13186 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
ax.bar throws when x axis is pandas datetime #13186
Closed
@david-waterworth

Description

@david-waterworth

Bug report

Bug summary

ax.bar throws error when x-axis is datetime, behaviour has changed between current master (throws error) and version 3.0.2 (no error)

Code for reproduction

import pandas as pd
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(20,10));
ax = fig.gca();

df = pd.DataFrame({'year':[2018,2018,2018],'month':[1,1,1], 'day':[1,2,3], 'value':[1,2,3]})
df['date'] = pd.to_datetime(df[['year', 'month', 'day']])

ax.bar(df['date'], df['value'], width=10,align='center')

Actual outcome

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-500999fd6ea9> in <module>
      8 df['date'] = pd.to_datetime(df[['year', 'month', 'day']])
      9 
---> 10 ax.bar(df['date'], df['value'], width=10,align='center')

~/matplotlib/lib/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1515     def inner(ax, *args, data=None, **kwargs):
   1516         if data is None:
-> 1517             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1518 
   1519         bound = new_sig.bind(ax, *args, **kwargs)

~/matplotlib/lib/matplotlib/axes/_axes.py in bar(self, x, height, width, bottom, align, **kwargs)
   2230             x0 = x
   2231             x = np.asarray(self.convert_xunits(x))
-> 2232             width = self._convert_dx(width, x0, x, self.convert_xunits)
   2233             if xerr is not None:
   2234                 xerr = self._convert_dx(xerr, x0, x, self.convert_xunits)

~/matplotlib/lib/matplotlib/axes/_axes.py in _convert_dx(dx, x0, xconv, convert)
   2055                 dx = [dx]
   2056                 delist = True
-> 2057             dx = [convert(x0 + ddx) - x for ddx in dx]
   2058             if delist:
   2059                 dx = dx[0]

~/matplotlib/lib/matplotlib/axes/_axes.py in <listcomp>(.0)
   2055                 dx = [dx]
   2056                 delist = True
-> 2057             dx = [convert(x0 + ddx) - x for ddx in dx]
   2058             if delist:
   2059                 dx = dx[0]

pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps._Timestamp.__add__()

ValueError: Cannot add integral value to Timestamp without freq.

Expected outcome

Matplotlib version
built matplotlib from source

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0