Skip to content

Method series.plot.hist doesn't work with date/datetime values #17372

Open
@prcastro

Description

@prcastro

Code Sample, a copy-pastable example if possible

pd.date_range('1/1/2011', periods=72, freq='H').to_series().plot.hist()

Problem description

The code above raises the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-53-175f21b4ff39> in <module>()
----> 1 pd.date_range('1/1/2011', periods=72, freq='H').to_series().plot.hist()

~/.anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in hist(self, bins, **kwds)
   2539         axes : matplotlib.AxesSubplot or np.array of them
   2540         """
-> 2541         return self(kind='hist', bins=bins, **kwds)
   2542 
   2543     def kde(self, **kwds):

~/.anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   2451                            colormap=colormap, table=table, yerr=yerr,
   2452                            xerr=xerr, label=label, secondary_y=secondary_y,
-> 2453                            **kwds)
   2454     __call__.__doc__ = plot_series.__doc__
   2455 

~/.anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   1892                  yerr=yerr, xerr=xerr,
   1893                  label=label, secondary_y=secondary_y,
-> 1894                  **kwds)
   1895 
   1896 

~/.anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1692         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   1693 
-> 1694     plot_obj.generate()
   1695     plot_obj.draw()
   1696     return plot_obj.result

~/.anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in generate(self)
    241     def generate(self):
    242         self._args_adjust()
--> 243         self._compute_plot_data()
    244         self._setup_subplots()
    245         self._make_plot()

~/.anaconda3/lib/python3.6/site-packages/pandas/plotting/_core.py in _compute_plot_data(self)
    350         if is_empty:
    351             raise TypeError('Empty {0!r}: no numeric data to '
--> 352                             'plot'.format(numeric_data.__class__.__name__))
    353 
    354         self.data = numeric_data

TypeError: Empty 'DataFrame': no numeric data to plot

Expected Output

A graph similar to:

pd.date_range('1/1/2011', periods=72, freq='H').to_series().hist()

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Linux
OS-release: 3.10.0-514.26.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.26
numpy: 1.12.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.0.2
openpyxl: 2.4.8
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.9999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions