Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
prcastro opened this issue Aug 29, 2017 · 3 comments
Open

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

prcastro opened this issue Aug 29, 2017 · 3 comments
Labels
Datetime Datetime data dtype Enhancement Visualization plotting

Comments

@prcastro
Copy link
Contributor

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

@gfyoung gfyoung added the Visualization plotting label Aug 29, 2017
@gfyoung
Copy link
Member

gfyoung commented Aug 29, 2017

Hmmm...this looks weird indeed, given the error message.

cc @TomAugspurger

@TomAugspurger
Copy link
Contributor

@prcastro take a look at pandas.plotting._core.MPLPlot_compute_plot_data to see if there's a way to include datetimes (and potentially time-deltas). This may have to depend on the type of plot and how many things are being plotted (dataframe vs. series).

@sinhrks
Copy link
Member

sinhrks commented Aug 29, 2017

Related to #8712.

If it is expected to output the freqs of the values, it should support other dtypes also?

@gfyoung gfyoung added the Error Reporting Incorrect or improved errors from pandas label Mar 1, 2019
@mroeschke mroeschke added Enhancement Datetime Datetime data dtype and removed Error Reporting Incorrect or improved errors from pandas labels Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Enhancement Visualization plotting
Projects
None yet
Development

No branches or pull requests

5 participants