将小部件与 pandas_bokeh 合并;收到 "ValueError" 条消息
Incorporating widgets with pandas_bokeh; getting "ValueError" message
我正在尝试将一些 bokeh
小部件与 pandas_bokeh
绘图合并到仪表板中,以便通过过滤以交互方式更新它们。但是,当我启动仪表板时,我得到一个空白的浏览器选项卡。这是我的代码:-
import numpy as np
import pandas as pd
import pandas_bokeh
from bokeh.io import show, curdoc
from bokeh.layouts import column, layout, row
from bokeh.models import DateRangeSlider, Dropdown
# Embedding plots in Jupyter/Colab Notebook
#pandas_bokeh.output_notebook()
# for exporting plots as HTML
#pandas_bokeh.output_file(filename)
#color palette
colors=['#FDE724','#D01C8B','#4DAC26']
#define the categorical variable
category_a = ['A','B','C']
category_b = ['X','Y','Z']
#set random seed to make the dataset reproducible
np.random.seed(42)
#create a dataset
#df_random = pd.DataFrame({
# 'id': np.arange(0, 15),
# 'month':np.random.randint(1, 12, 15),
# 'sensor_1': np.random.uniform(0, 1,15),
# 'sensor_2': np.random.uniform(10, 15, 15),
# 'sensor_3': np.random.randint(0, 20, 15),
# 'category': np.random.choice(category, 15, p=[0.2, 0.4, 0.4]),
#})
df_random2 = pd.DataFrame({
'id': np.arange(0, 30),
'date': pd.date_range(start='1/1/2021', periods=30, freq='D'),
'month':np.random.randint(1, 12, 30),
'sensor_1': np.random.uniform(0, 1,30),
'sensor_2': np.random.uniform(10, 15, 30),
'sensor_3': np.random.randint(0, 20, 30),
'categorya': np.random.choice(category_a, 30, p=[0.2, 0.4, 0.4]),
'categoryb': np.random.choice(category_b, 30, p=[0.6, 0.2, 0.2]),
})
#set index to id column
df_random2=df_random2.set_index('id')
df_random2.shape
df_random2.head()
mindate=df_random2['date'].min()
maxdate=df_random2['date'].max()
menucols = [("Category A", "categorya"),("Category B","categoryb")]
date_range_slider = DateRangeSlider(value=(mindate, maxdate),
start=mindate, end=maxdate)
category_picker = Dropdown(label = "Column select", button_type="default", menu=menucols)
# Plot1 - Line plot
p_line= df_random2.groupby(['date']).mean().plot_bokeh(kind="line",y="sensor_2",color='#d01c8b',plot_data_points=True,show_figure=False)
# Plot2- Barplot
p_bar = df_random2.groupby(['date']).mean().plot_bokeh(kind="bar",y='sensor_2', colormap=colors,show_figure=False)
# Plot3- stacked bar chart
df_sensor=df_random2.drop(['date','month','categorya'],axis=1)
p_stack=df_sensor.groupby(['categoryb']).mean().plot_bokeh(kind='barh', stacked=True,colormap=colors,show_figure=False)
#Plot4- Scatterplot
p_scatter = df_random2.plot_bokeh(kind="scatter", x="month", y="sensor_2",category="categoryb",colormap=colors,show_figure=False)
#Plot5- Pie chart
p_pie= df_random2.groupby(['categoryb']).mean().plot_bokeh.pie(y='sensor_1',colormap=colors,show_figure=False)
#Plot6- Histogram
p_hist=df_sensor.plot_bokeh(kind='hist', histogram_type="stacked",bins=6,colormap=colors, show_figure=False)
widgets = [date_range_slider,category_picker]
#Make Dashboard with Grid Layout:
plots=pandas_bokeh.plot_grid([[widgets],[p_line, p_bar,p_stack],[p_scatter, p_pie,p_hist]], plot_width=400)
#show(bokehlayout)
curdoc().add_root(plots)
curdoc().title = "layout"
这是我收到的错误消息:-
ValueError: Only LayoutDOM items can be inserted into a column. Tried to insert: [DateRangeSlider(id='1002', ...), Dropdown(id='1003', ...)] of type <class 'list'>
谁能帮我理解为什么我会收到这条消息,也许我可以礼貌地请别人建议对我的代码进行一些修改以使其正常工作?
man, pandas_bokeh 用于基本的、迷你的想法。如果您想立即绘制图表,请使用它。它有效。但如果你想使用其他想法,如小部件、工具等,请使用散景本身。消息出现是因为您需要使用散景布局。 pandas_bokeh 不支持所有内容,它是第 3 方附加组件。
您的代码 from bokeh.layouts import layout
和
plots = layout([[widgets],[p_line, p_bar,p_stack],[p_scatter, p_pie,p_hist]])
curdoc().add_root(plots)
我正在尝试将一些 bokeh
小部件与 pandas_bokeh
绘图合并到仪表板中,以便通过过滤以交互方式更新它们。但是,当我启动仪表板时,我得到一个空白的浏览器选项卡。这是我的代码:-
import numpy as np
import pandas as pd
import pandas_bokeh
from bokeh.io import show, curdoc
from bokeh.layouts import column, layout, row
from bokeh.models import DateRangeSlider, Dropdown
# Embedding plots in Jupyter/Colab Notebook
#pandas_bokeh.output_notebook()
# for exporting plots as HTML
#pandas_bokeh.output_file(filename)
#color palette
colors=['#FDE724','#D01C8B','#4DAC26']
#define the categorical variable
category_a = ['A','B','C']
category_b = ['X','Y','Z']
#set random seed to make the dataset reproducible
np.random.seed(42)
#create a dataset
#df_random = pd.DataFrame({
# 'id': np.arange(0, 15),
# 'month':np.random.randint(1, 12, 15),
# 'sensor_1': np.random.uniform(0, 1,15),
# 'sensor_2': np.random.uniform(10, 15, 15),
# 'sensor_3': np.random.randint(0, 20, 15),
# 'category': np.random.choice(category, 15, p=[0.2, 0.4, 0.4]),
#})
df_random2 = pd.DataFrame({
'id': np.arange(0, 30),
'date': pd.date_range(start='1/1/2021', periods=30, freq='D'),
'month':np.random.randint(1, 12, 30),
'sensor_1': np.random.uniform(0, 1,30),
'sensor_2': np.random.uniform(10, 15, 30),
'sensor_3': np.random.randint(0, 20, 30),
'categorya': np.random.choice(category_a, 30, p=[0.2, 0.4, 0.4]),
'categoryb': np.random.choice(category_b, 30, p=[0.6, 0.2, 0.2]),
})
#set index to id column
df_random2=df_random2.set_index('id')
df_random2.shape
df_random2.head()
mindate=df_random2['date'].min()
maxdate=df_random2['date'].max()
menucols = [("Category A", "categorya"),("Category B","categoryb")]
date_range_slider = DateRangeSlider(value=(mindate, maxdate),
start=mindate, end=maxdate)
category_picker = Dropdown(label = "Column select", button_type="default", menu=menucols)
# Plot1 - Line plot
p_line= df_random2.groupby(['date']).mean().plot_bokeh(kind="line",y="sensor_2",color='#d01c8b',plot_data_points=True,show_figure=False)
# Plot2- Barplot
p_bar = df_random2.groupby(['date']).mean().plot_bokeh(kind="bar",y='sensor_2', colormap=colors,show_figure=False)
# Plot3- stacked bar chart
df_sensor=df_random2.drop(['date','month','categorya'],axis=1)
p_stack=df_sensor.groupby(['categoryb']).mean().plot_bokeh(kind='barh', stacked=True,colormap=colors,show_figure=False)
#Plot4- Scatterplot
p_scatter = df_random2.plot_bokeh(kind="scatter", x="month", y="sensor_2",category="categoryb",colormap=colors,show_figure=False)
#Plot5- Pie chart
p_pie= df_random2.groupby(['categoryb']).mean().plot_bokeh.pie(y='sensor_1',colormap=colors,show_figure=False)
#Plot6- Histogram
p_hist=df_sensor.plot_bokeh(kind='hist', histogram_type="stacked",bins=6,colormap=colors, show_figure=False)
widgets = [date_range_slider,category_picker]
#Make Dashboard with Grid Layout:
plots=pandas_bokeh.plot_grid([[widgets],[p_line, p_bar,p_stack],[p_scatter, p_pie,p_hist]], plot_width=400)
#show(bokehlayout)
curdoc().add_root(plots)
curdoc().title = "layout"
这是我收到的错误消息:-
ValueError: Only LayoutDOM items can be inserted into a column. Tried to insert: [DateRangeSlider(id='1002', ...), Dropdown(id='1003', ...)] of type <class 'list'>
谁能帮我理解为什么我会收到这条消息,也许我可以礼貌地请别人建议对我的代码进行一些修改以使其正常工作?
man, pandas_bokeh 用于基本的、迷你的想法。如果您想立即绘制图表,请使用它。它有效。但如果你想使用其他想法,如小部件、工具等,请使用散景本身。消息出现是因为您需要使用散景布局。 pandas_bokeh 不支持所有内容,它是第 3 方附加组件。
您的代码 from bokeh.layouts import layout
和
plots = layout([[widgets],[p_line, p_bar,p_stack],[p_scatter, p_pie,p_hist]])
curdoc().add_root(plots)