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

egg*_*ert 5 python bokeh

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

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)
Run Code Online (Sandbox Code Playgroud)

不幸的是它无法正确渲染:

在此输入图像描述

我尝试过设置 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,
)
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用缩放工具时,控制台中出现以下错误:

Uncaught Error: Number property 'start' given invalid value: 
Uncaught TypeError: Cannot read property 'indexOf' of null
Run Code Online (Sandbox Code Playgroud)

我使用的是 Bokeh 0.12.3。

big*_*dot 2

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

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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述