- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一系列带有时间戳的特定事件,我想创建一个热图:
我的数据(作为 pandas 数据框 z.head()
):
date hour i
0 2016-01-15 13 1
1 2016-01-15 13 1
2 2016-01-15 12 1
3 2016-01-15 10 1
4 2016-01-15 10 1
我失败的尝试:
from bokeh._legacy_charts import HeatMap, output_file, show
hm = HeatMap(z.head(), x='date', y='hour', values='i', stat='count')
异常(exception)情况:
AttributeError Traceback (most recent call last)
<ipython-input-98-83c7e9319496> in <module>()
----> 1 hm = HeatMap(z.head(), x='date', y='hour', values='i', stat='count')
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/builders/heatmap_builder.py in HeatMap(data, x, y, values, stat, xgrid, ygrid, hover_tool, hover_text, **kw)
90 kw['values'] = values
91 kw['stat'] = stat
---> 92 chart = create_and_build(HeatMapBuilder, data, xgrid=xgrid, ygrid=ygrid, **kw)
93
94 if hover_tool:
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/builder.py in create_and_build(builder_class, *data, **kws)
65 chart_kws = { k:v for k,v in kws.items() if k not in builder_props}
66 chart = Chart(**chart_kws)
---> 67 chart.add_builder(builder)
68 chart.start_plot()
69
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/chart.py in add_builder(self, builder)
150 def add_builder(self, builder):
151 self._builders.append(builder)
--> 152 builder.create(self)
153
154 def add_ranges(self, dim, range):
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/builder.
510 # call methods that allow customized setup by subc
511 self.setup()
--> 512 self.process_data()
513
514 # create and add renderers to chart
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/builders
169 # color by the values selection
170 self.attributes['color'].setup(data=self._data.sou
--> 171 columns=self.values
172 self.attributes['color'].add_bin_labels(self._data
173
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/attribut
187
188 if self.columns is not None and self.data is not N
--> 189 self.attr_map = self._create_attr_map(self.dat
190
191 def update_data(self, data):
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/attribut
158 """Creates map between unique values and available
159
--> 160 self._generate_items(df, columns)
161 iterable = self._setup_iterable()
162
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/attribut
230
231 self.bins = Bins(source=ColumnDataSource(d
--> 232 bin_count=len(self.iterab
233
234 if self.sort:
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/stats.py
309 properties['source'] = source
310
--> 311 super(Bins, self).__init__(**properties)
312
313 def _get_stat(self):
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/stats.py
54
55 super(Stat, self).__init__(**properties)
---> 56 self._refresh()
57
58 def _refresh(self):
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/stats.py
60 if self.get_data() is not None:
61 self.update()
---> 62 self.calculate()
63
64 def set_data(self, data, column=None):
/home/user/.local/lib/python3.4/site-packages/bokeh/charts/stats.py
342 if self.source is not None:
343 # add bin column to data source
--> 344 self.source.add(binned.tolist(), name=self.bin
345 df = self.source.to_df()
346 else:
AttributeError: 'Categorical' object has no attribute 'tolist'
Bokeh 是 0.11 版本,用 pip3 安装。我究竟做错了什么?谢谢。
pip3 install --user --force-reinstall --upgrade bokeh
。仍然没有快乐。完整代码:
import pandas as pd
from bokeh.charts import HeatMap, output_file, show
z = pd.DataFrame()
z['date'] = ['2016-01-15', '2016-01-13', '2016-01-11', '2016-01-14', '2016-01-15']
z['hour'] = [12, 10, 11, 3, 0]
z['i'] = [1, 1, 1, 1, 1]
output_file('/tmp/test.html')
hm = HeatMap(z, x='date', y='hour', stat='count')
show(hm)
并使用 python3 运行:
Traceback (most recent call last):
File "so.py", line 10, in <module>
hm = HeatMap(z, x='date', y='hour', stat='count')
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/builders/heatmap_builder.py", line 92, in HeatMap
chart = create_and_build(HeatMapBuilder, data, xgrid=xgrid, ygrid=ygrid, **kw)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/builder.py", line 67, in create_and_build
chart.add_builder(builder)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/chart.py", line 152, in add_builder
builder.create(self)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/builder.py", line 512, in create
self.process_data()
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/builders/heatmap_builder.py", line 171, in process_data
columns=self.values.selection)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/attributes.py", line 189, in setup
self.attr_map = self._create_attr_map(self.data.to_df(), self.columns)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/attributes.py", line 160, in _create_attr_map
self._generate_items(df, columns)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/attributes.py", line 232, in _generate_items
bin_count=len(self.iterable), aggregate=False)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/stats.py", line 311, in __init__
super(Bins, self).__init__(**properties)
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/stats.py", line 56, in __init__
self._refresh()
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/stats.py", line 62, in _refresh
self.calculate()
File "/home/ktx/.local/lib/python3.4/site-packages/bokeh/charts/stats.py", line 344, in calculate
self.source.add(binned.tolist(), name=self.bin_column)
AttributeError: 'Categorical' object has no attribute 'tolist'
最佳答案
bigreddot 是对的。如果你有 0.11,你不应该有 legacy_charts
。正确更新 Bokeh 后,这应该可以工作:
from bokeh.charts import HeatMap, output_file, show
import pandas as pd
output_file('test.html')
hm = HeatMap(z, x='date', y='hour', values='i', stat='count')
show(hm)
关于python - Bokeh 热图的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35189203/
我想要类似于以下伪代码的东西: while input is not None and timer = 5: print "took too long" else: print inp
如何将 MainEngine Observable 转换为 Cold?来自这个例子: public IObservable MainEngine { get
自从手表被发明以来,表盘的方圆之争就始终没有停下来过,在漫长的岁月中,无论是方形还是圆形表盘,人们都为其寻找到足够多的设计元素,让其肆意成长,这种生机与活力后来也延续到了智能手表上,在2014年,这
我正在学习 CUDA,试图解决一些标准问题。例如,我正在使用以下代码求解二维扩散方程。但我的结果与标准结果不同,我无法弄清楚。 //kernel definition __global__ void
我的 Web 应用程序使用 native dll 来实现其部分功能(其位置在 PATH 中提供)。一切正常,直到我对 WAR 进行更改并且 JBoss 热部署此 WAR。此时dll已经找不到了,需要手
我看到这个问题here 。这是关于实现每个发出的项目的延迟。这是根据accepted answer如何实现的: Observable.zip(Observable.range(1, 5) .g
我最近一直在进行冷迁移...这意味着我无法在进行迁移时从应用程序级别读取/写入数据库(维护页面)。 这样就不会因为更改结构而发生错误,而且如果负载很大,我也不希望 mysql 在迁移过程中崩溃。 我的
我是一名优秀的程序员,十分优秀!