gpt4 book ai didi

python - Bokeh - 仅在单击时加载标签

转载 作者:行者123 更新时间:2023-12-03 15:00:13 25 4
gpt4 key购买 nike

我对 Bokeh 比较陌生,并编写了一个函数,允许用户使用选项卡选择要绘制的数据。函数make_plot()下面的速度相对较慢,因为要绘制的数据集很大,而且我有 30 个选项卡,因此我只想在用户单击选项卡时创建该图(而不是预加载所有 30 个图)。我没有使用 javascript 的经验,有没有办法在 Python 中做到这一点?

这是我的功能:

def plot_all_outputs(sa_dict, min_val=0.01, top=100, stacked=True,
error_bars=True, log_axis=True,
highlighted_parameters=[]):
"""
This function calls make_plot() for all the sensitivity
analysis output files and lets you choose which output to view
using tabs

Parameters:
-----------
sa_dict : a dictionary with all the sensitivity analysis
results
min_val : a float indicating the minimum sensitivity value
to be shown
top : integer indicating the number of parameters to
display (highest sensitivity values)
stacked1 : Boolean indicating in bars should be stacked for
each parameter.
error_bars : Booelan indicating if error bars are shown (True)
or are omitted (False)
log_axis : Boolean indicating if log axis should be used
(True) or if a linear axis should be used (False).
highlighted_parameters : List of strings indicating which parameter wedges
will be highlighted

Returns:
--------
p : a bokeh plot generated with plotting.make_plot() that includes tabs
for all the possible outputs.
"""

tabs_dictionary = {}
outcomes_array = []

for files in sa_dict.keys():
outcomes_array.append(sa_dict[files][0])

for i in range(len(sa_dict)):
p = make_plot(outcomes_array[i],
top=top,
minvalues=min_val,
stacked=stacked,
errorbar=error_bars,
lgaxis=log_axis,
highlight=highlighted_parameters
)
tabs_dictionary[i] = Panel(child=p, title=sa_dict.keys()[i])

tabs = Tabs(tabs=tabs_dictionary.values())
p = show(tabs)

return p

最佳答案

为了在选项卡选择上绘图,您可以将绘图代码添加到 on_change标签的属性:

tabs = Tabs(tabs=[tab_01,tab_02])

def tabs_on_change(attr, old, new):
print("the active panel is " + str(tabs.active))
plot_tab_function(tabs.active) #<--your plotting code here
tabs.on_change('active', tabs_on_change)
在这里, tabs.active是所选选项卡的索引。

关于python - Bokeh - 仅在单击时加载标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35932053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com