简体   繁体   English

散景categorical_bar_stacked

[英]Bokeh categorical_bar_stacked

I need to adapt the Bokeh Example of stacked chart to my data, I've followed the same pattern but when I ran the code the following error has rise ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [5, 6] 我需要使堆叠图表的Bokeh示例适应我的数据,我遵循了相同的模式,但是当我运行代码时,出现了以下错误ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [5, 6] ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [5, 6]

Below my code, it is a snippet of my data, the data is spread for several days 在我的代码下方,这是我的数据的一部分,数据分散了几天

from bokeh.core.properties import value
from bokeh.io import show, output_file
from bokeh.plotting import figure
output_file("stacked.html")

time = ['2018-08-06 00:00:00', '2018-08-06 01:00:00', '2018-08-06 02:00:00',
    '2018-08-06 03:00:00', '2018-08-06 04:00:00', '2018-08-06 05:00:00']
boards = ['GPHB_00-40', 'GPHB_41-60', 'GPHB_61-80', 'GPHB_81-90', 'GPHB_91-100']
colors = ['#2b83ba', '#abdda4', '#ffffbf', '#fdae61', '#d7191c']

data = {'time'         : time,
        'GPHB_00-40'   : [95, 99, 99, 100, 100, 100, 100, 95, 69, 55],
        'GPHB_41-60'   : [4,  1,  1,  0,   0,   0,   0,   4,  20, 34],
        'GPHB_61-80'   : [1,  0,  0,  0,   0,   0,   0,   1,  5,  8 ],
        'GPHB_81-90'   : [0,  0,  0,  0,   0,   0,   0,   0,  4,  2 ],
        'GPHB_91-100'  : [0,  0,  0,  0,   0,   0,   0,   0,  2,  1 ]}

p = figure(x_range=time, plot_height=250, title="Boards Load",
           toolbar_location=None, tools="")

p.vbar_stack(boards, x='time', width=0.9, color=colors, source=data,
             legend=[value(x) for x in time])

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"

show(p)

I've found the solution, there was a mistake in the code 我找到了解决方案,代码中有错误

p.vbar_stack(boards, x='time', width=0.9, color=colors, source=data,
         legend=[value(x) for x in time])

the reference on time was wrond it should be reference to boards 准时的参考是错误的,应该参考董事会

p.vbar_stack(boards, x='time', width=0.9, color=colors, source=data,
         legend=[value(x) for x in boards])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM