【发布时间】:2018-07-18 01:21:55
【问题描述】:
我是第一次尝试使用 Bokeh 库,但我发现文档不是那么简单。
我有一个数据框 df:
A B C
1 4 6
2 3 5
3 2 4
4 1 3
我想创建一个带有集成小部件的 Boken 直方图,以便用户选择要显示的列(A B 或 C)。
我写了以下内容:
import pandas as pd
d= {'A': [1, 2,3,4], 'cB': [4,3,2,1], 'C' : [6,5,4,3]}
df = pd.DataFrame(data=d)
names = ["A","B", "C"]
from bokeh.io import output_file, show
from bokeh.layouts import widgetbox
from bokeh.models.widgets import MultiSelect
from bokeh.io import curdoc
# drop table
curdoc().clear()
# create drop down #define witget
output_file("multi_select.html")
Field = MultiSelect(title="Features:", value=["A"],
options=names)
show(widgetbox(Field))
from bokeh.charts import Histogram, output_file, show
from bokeh.layouts import row, layout
from bokeh.models.sources import ColumnDataSource
curdoc().clear()
source = ColumnDataSource(df)
hist = Histogram(df, values="A", title="A", plot_width=400) #not sure why I cannot use source instead of df
output_file('hist.html')
show(hist)
所以现在我需要将绘图与小部件连接起来。
我尝试了以下方法,但似乎不起作用。
hist = Histogram(df, values={'Field'}, title={'Field'}, plot_width=400)
欢迎任何其他不使用散景库的解决方案,我使用 Spyder 编辑器运行代码并使用 IE 来可视化结果。
【问题讨论】:
-
您要一次选择单列还是多列。 @A.Papa
-
最好是多列一次比较分布,但我不确定是否可能。
标签: python histogram bokeh interactive