加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-20 13:14:42 所属栏目:Python 来源:网络整理
导读:我正在尝试绘制以下简单的热图: data = { 'value': [1,2,3,4,5,6],'x': [datetime(2016,10,25,0),datetime(2016,8,16,0)],'y': ['param1','param1','param2','param2']}hm = HeatMap(data,x='x',y='y',values='value',stat=None)output_file('heatmap.html'
我正在尝试绘制以下简单的热图:

data = {
    'value': [1,2,3,4,5,6],'x': [datetime(2016,10,25,0),datetime(2016,8,16,0)],'y': ['param1','param1','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),width=12000000,height=1,)

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

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

我使用的是Bokeh 0.12.3.

解决方法

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

from datetime import datetime

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

data = {
    'value': [1,'param2']
}

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

EIGHT_HOURS = 8*60*60*1000

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

show(p)

enter image description here

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读