散景直方图将不会绘制 [英] Bokeh histogram will not plot

查看:75
本文介绍了散景直方图将不会绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题似乎与此帖子完全一样(尽管列的类型可能不同):

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

无法在Ubuntu 14.04上绘制直方图

代码直接来自文档 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...

我的系统是SUSE.只是试图绘制熊猫df系列中日期时间的简单直方图.

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]')

任何帮助将不胜感激.

干杯n谢谢

推荐答案

不要使用bokeh.charts(现在是单独的bkcharts项目),包括Histogram. bkcharts项目目前已已放弃且未维护.但是,使用bokeh.plotting创建直方图非常简单,这是Bokeh的稳定且得到良好支持的核心API:

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)

或者,如果您希望在Bokeh上使用非常高级的统计图表API,请查看以下选项:

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

  • Holoviews
  • PandasBokeh
  • Chartify

这篇关于散景直方图将不会绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆