散景分类_bar_stacked

问题描述 投票:0回答:1

我需要调整叠加图表的Bokeh Example到我的数据,我遵循相同的模式但是当我运行代码时,以下错误已经上升ValueError: Keyword argument sequences for broadcasting must all be the same lengths. Got lengths: [5, 6]

在我的代码下面,它是我的数据片段,数据传播了好几天

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)
python charts bokeh
1个回答
0
投票

我找到了解决方案,代码中有一个错误

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

时间参考是错误的,应该参考董事会

p.vbar_stack(boards, x='time', width=0.9, color=colors, source=data,
         legend=[value(x) for x in boards])
© www.soinside.com 2019 - 2024. All rights reserved.