Javascript ) + 1:] r=p.vbar(底部=堆栈(*col_acc),顶部=堆栈(col,*col_acc), x='index',宽度=0.9,颜色=颜色,源=源) 列附件(列) renderers.append(r) p、 yaxis.formatter=
) + 1:] r=p.vbar(底部=堆栈(*col_acc),顶部=堆栈(col,*col_acc), x='index',宽度=0.9,颜色=颜色,源=源) 列附件(列) renderers.append(r) p、 yaxis.formatter=数字格式化程序(格式='(0.00')) 选择=选择(title=“Fruit:”,值=初始值,选项=选择列表) 选择.js_on_change('value',CustomJS(args=dict(d_map=d_map,renders=renders)), 代码=”“ const Stack=Bokeh.Models('Stack'); const col_acc=[]; d_映射[cb_obj.value].forEach((col,idx)=>{ const{glyph}=渲染器[idx]; glyph.bottom={expr:newstack({fields:col_acc}}); col_acc.push(col); glyph.top={expr:newstack({fields:col_acc}}); }); """)) col=列(选择) 布局=行(列,p) 显示(布局)Javascript ) + 1:] r=p.vbar(底部=堆栈(*col_acc),顶部=堆栈(col,*col_acc), x='index',宽度=0.9,颜色=颜色,源=源) 列附件(列) renderers.append(r) p、 yaxis.formatter=,javascript,python,bokeh,bokehjs,Javascript,Python,Bokeh,Bokehjs,) + 1:] r=p.vbar(底部=堆栈(*col_acc),顶部=堆栈(col,*col_acc), x='index',宽度=0.9,颜色=颜色,源=源) 列附件(列) renderers.append(r) p、 yaxis.formatter=数字格式化程序(格式='(0.00')) 选择=选择(title=“Fruit:”,值=初始值,选项=选择列表) 选择.js_on_change('value',CustomJS(args=dict(d_map=d_map,renders=re
谢谢你,尤金。工作得很有魅力。额外的积分用于使其准备在输入方面扩大规模!谢谢你,尤金。工作得很有魅力。额外的积分用于使其准备在输入方面扩大规模!
import pandas as pd
import numpy as np
import datetime
from bokeh.io import show
from bokeh.layouts import row, column
from bokeh.models import ColumnDataSource, CustomJS
from bokeh.plotting import figure, ColumnDataSource, show
from bokeh.models.widgets import Select
from bokeh.models import Label, Title, NumeralTickFormatter
df = pd.DataFrame.from_dict(
{
'Apples_green': {'2018': 100, '2019': 150, '2020': 200},
'Apples_red': {'2018': 200, '2019': 75, '2020': 25},
'Oranges_green': {'2018': 25, '2019': 60, '2020': 70},
'Oranges_red': {'2018': 100, '2019': 80, '2020': 10}
}
)
#List of columns for apples
initial_col = [i for i in df.columns.tolist() if i.startswith('Apples')]
selection_list = ["Apples", "Oranges"]
d_map = {
'Apples':['Apples_green', 'Apples_red'],
'Oranges':['Oranges_green', 'Oranges_red']
}
source = ColumnDataSource(df)
p = figure(plot_width=350, plot_height = 300,
x_range=df.index.drop_duplicates().tolist())
p.vbar_stack(initial_col, x='index',
width=0.9, color=['green', 'red'], source=source)
p.yaxis.formatter = NumeralTickFormatter(format='(0.00)')
select = Select(title="Fruit:", value=selection_list[0], options=selection_list)
select.js_on_change('value', CustomJS(args=dict(source=source, select=select, d_map = d_map), code="""
// print the selectd value of the select widget -
// this is printed in the browser console.
// cb_obj is the callback object, in this case the select
// widget. cb_obj.value is the selected value.
console.log(' changed selected option', cb_obj.value);
// create a new variable for the data of the column data source
// this is linked to the plot
var data = source.data;
// allocate the selected column to the field for the y values
data['{}'] = data[d_map[cb_obj.value]];
// register the change - this is required to process the change in
// the y values
source.change.emit();
""".format(d_map[selection_list[0]])))
col = column(select)
layout = row(col, p)
show(layout)