Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh histogram will not plot

My issue seems exactly like this post (albeit column types may be different):

Cannot plot Histogram on Ubuntu 14.04

The code is straight out of the docs http://docs.bokeh.org/en/0.10.0/docs/user_guide/charts.html#histograms

I couldn't comment on that post so needed to ask again if a solution was found...

My system is SUSE. Just trying to plot a simple histogram of datetimes from a pandas df series.

>>>df
           ACQ_DATE
0       2017-01-28
1       2017-01-28
...            ...
456365  2017-07-25
456366  2017-07-25

>>>hist = Histogram(df['ACQ_DATE'], title="Fire Frequency")

2017-08-22 11:56:15,240 Error running application handler <bokeh.application.handlers.script.ScriptHandler object at 0x2b6cc2c8f358>:     expected an element of either Column(Float) or Column(String), got array(['2017-    01-28T00:00:00.000000000', '2017-01-28T00:00:00.000000000',
   '2017-01-28T00:00:00.000000000', ...,
   '2017-07-25T00:00:00.000000000', '2017-07-25T00:00:00.000000000',
   '2017-07-25T00:00:00.000000000'], dtype='datetime64[ns]')
File "properties.py", line 676, in validate:
raise ValueError("expected an element of either %s, got %r" % (nice_join    (self.type_params), value)) Traceback (most recent call last):
  File "/home/byed/venv36/lib/python3.6/site-    packages/bokeh/application/handlers/code_runner.py", line 81, in run
exec(self._code, module.__dict__)
  File "/home/byed/job/fire/report_fire_points.py", line 118, in <module>
    hist = Histogram(df['ACQ_DATE'], title="Fire Frequency")  #,     tools='pan,wheel_zoom,box_select,reset')
  File "/home/byed/venv36/lib/python3.6/site-    packages/bkcharts/builders/histogram_builder.py", line 107, in Histogram
    return create_and_build(HistogramBuilder, data, **kw)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/builder.py", line 56, in create_and_build
    chart.add_builder(builder)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/chart.py", line 155, in add_builder
    builder.create(self)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/builder.py", line 512, in create
    chart.add_renderers(self, renderers)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/chart.py", line 150, in add_renderers
    self.renderers += renderers
  File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/containers.py", line 76, in wrapper
    result = func(self, *args, **kwargs)
  File "/home/byed/venv36/lib/python3.6/site-    packages/bokeh/core/property/containers.py", line 172, in __iadd__
    return super(PropertyValueList, self).__iadd__(y)
  File "/home/byed/venv36/lib/python3.6/site-   packages/bkcharts/builders/bar_builder.py", line 221, in yield_renderers
    **group_kwargs)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/glyphs.py", line 950, in __init__
    super(HistogramGlyph, self).__init__(**kwargs)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/glyphs.py", line 490, in __init__
    super(AggregateGlyph, self).__init__(**kwargs)
  File "/home/byed/venv36/lib/python3.6/site-packages/bkcharts/models.py", line 83, in __init__
    super(CompositeGlyph, self).__init__(**properties)
  File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/has_props.py", line 246, in __init__
    setattr(self, name, value)
  File "/home/byed/venv36/lib/python3.6/site- packages/bokeh/core/has_props.py", line 274, in __setattr__
    super(HasProps, self).__setattr__(name, value)
  File "/home/byed/venv36/lib/python3.6/site-   packages/bokeh/core/property/descriptors.py", line 495, in __set__
    self._internal_set(obj, value, setter)
  File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/descriptors.py", line 713, in _internal_set
    value = self.property.prepare_value(obj, self.name, value)
  File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/bases.py", line 290, in prepare_value
    raise e
  File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/property/bases.py", line 283, in prepare_value
self.validate(value)
  File "/home/byed/venv36/lib/python3.6/site-packages/bokeh/core/properties.py", line 676, in validate
    raise ValueError("expected an element of either %s, got %r" % (nice_join   (self.type_params), value))
    ValueError: expected an element of either Column(Float) or Column(String),   got array(['2017-01-28T00:00:00.000000000', '2017-01-28T00:00:00.000000000',
   '2017-01-28T00:00:00.000000000', ...,
   '2017-07-25T00:00:00.000000000', '2017-07-25T00:00:00.000000000',
   '2017-07-25T00:00:00.000000000'], dtype='datetime64[ns]')

Any help would be much appreciated.

Cheers n Thanks

like image 603
byezy Avatar asked Dec 14 '22 21:12

byezy


1 Answers

Don't use bokeh.charts (now a separate bkcharts project), including Histogram. The bkcharts project is currently abandoned and unmaintained. However, it's pretty trivial to create histograms using bokeh.plotting which is the stable and well-supported core API of Bokeh:

import numpy as np
from bokeh.io import show, output_file
from bokeh.plotting import figure

data = np.random.normal(0, 0.5, 1000)
hist, edges = np.histogram(data, density=True, bins=50)

p = figure()
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="white")

output_file("hist.html")
show(p)

enter image description here

Alternatively, if you want a very-high level statistical charting API on top of Bokeh, then check out these options:

  • Holoviews
  • PandasBokeh
  • Chartify
like image 179
bigreddot Avatar answered Dec 16 '22 11:12

bigreddot