gpt4 book ai didi

python - 无法使用日期时间 x 轴在 Bokeh 中绘制热图

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:23 24 4
gpt4 key购买 nike

我正在尝试绘制以下简单的热图:

data = {
'value': [1, 2, 3, 4, 5, 6],
'x': [datetime(2016, 10, 25, 0, 0),
datetime(2016, 10, 25, 8, 0),
datetime(2016, 10, 25, 16, 0),
datetime(2016, 10, 25, 0, 0),
datetime(2016, 10, 25, 8, 0),
datetime(2016, 10, 25, 16, 0)],
'y': ['param1', 'param1', 'param1', 'param2', 'param2', 'param2']
}
hm = HeatMap(data, x='x', y='y', values='value', stat=None)
output_file('heatmap.html')
show(hm)

不幸的是它没有正确呈现:

enter image description here

我已经尝试设置 x_range,但似乎没有任何效果。

我已经设法用下面的代码得到了一些东西:

d1 = data['x'][0]
d2 = data['x'][-1]

p = figure(
x_axis_type="datetime", x_range=(d1, d2), y_range=data['y'],
tools='xpan, xwheel_zoom, reset, save, resize,'
)

p.rect(
source=ColumnDataSource(data), x='x', y='y', width=12000000, height=1,
)

然而,当我尝试使用缩放工具时,我在控制台中收到以下错误:

Uncaught Error: Number property 'start' given invalid value: 
Uncaught TypeError: Cannot read property 'indexOf' of null

我使用的是 Bokeh 0.12.3。

最佳答案

bokeh.charts,包括 HeatMap 已于 2017 年弃用并删除。您应该使用稳定且受支持的 bokeh.plotting API。使用上面的数据,一个完整的示例:

from datetime import datetime

from bokeh.plotting import figure, show
from bokeh.transform import linear_cmap

data = {
'value': [1, 2, 3, 4, 5, 6],
'x': [datetime(2016, 10, 25, 0, 0),
datetime(2016, 10, 25, 8, 0),
datetime(2016, 10, 25, 16, 0),
datetime(2016, 10, 25, 0, 0),
datetime(2016, 10, 25, 8, 0),
datetime(2016, 10, 25, 16, 0)],
'y': ['param1', 'param1', 'param1', 'param2', 'param2', 'param2']
}

p = figure(x_axis_type='datetime', y_range=('param1', 'param2'))

EIGHT_HOURS = 8*60*60*1000

p.rect(x='x', y='y', width=EIGHT_HOURS, height=1, line_color="white",
fill_color=linear_cmap('value', 'Spectral6', 1, 6), source=data)

show(p)

enter image description here

关于python - 无法使用日期时间 x 轴在 Bokeh 中绘制热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40243460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com