2017-09-19 31 views
0

次のスクリプトを使用して、checkboxGroupを使用してマルチラインをプロットしました。 私のボケのバージョンは0.12.7Bokeh - checkboxGroupプロット:デフォルトのプロットのみ選択

です。唯一の問題は、すべてのラインをデフォルトとして視覚化し、2つのボックスをオフにしていることです(3つのラインプロットの代わりに2つのラインプロットが表示されます)。

アクティブなもの(l0とl2)のみをデフォルトとして表示する方法はありますか?

import numpy as np 

from bokeh.io import output_file, show 
from bokeh.layouts import row 
from bokeh.palettes import Viridis3 
from bokeh.plotting import figure 
from bokeh.models import CheckboxGroup, CustomJS 

output_file("line_on_off.html", title="line_on_off.py example") 

p = figure() 
props = dict(line_width=4, line_alpha=0.7) 
x = np.linspace(0, 4 * np.pi, 100) 
l0 = p.line(x, np.sin(x), color=Viridis3[0], legend="Line 0", **props) 
l1 = p.line(x, 4 * np.cos(x), color=Viridis3[1], legend="Line 1", **props) 
l2 = p.line(x, np.tan(x), color=Viridis3[2], legend="Line 2", **props) 

checkbox = CheckboxGroup(labels=["Line 0", "Line 1", "Line 2"], 
         active=[0, 2], width=100) 
checkbox.callback = CustomJS.from_coffeescript(args=dict(l0=l0, l1=l1, l2=l2, checkbox=checkbox), code=""" 
l0.visible = 0 in checkbox.active; 
l1.visible = 1 in checkbox.active; 
l2.visible = 2 in checkbox.active; 
""") 

layout = row(checkbox, p) 
show(layout) 

答えて

1

CustomJSコードは、チェックボックスがクリックするだけを実行します。あなたは線の一部は、デフォルトでは表示されないようにしたいのであれば、あなたは自分でそれを設定する必要があります。

import numpy as np 

from bokeh.io import output_file, show 
from bokeh.layouts import row 
from bokeh.palettes import Viridis3 
from bokeh.plotting import figure 
from bokeh.models import CheckboxGroup, CustomJS 

output_file("line_on_off.html", title="line_on_off.py example") 

p = figure() 
props = dict(line_width=4, line_alpha=0.7) 
x = np.linspace(0, 4 * np.pi, 100) 
l0 = p.line(x, np.sin(x), color=Viridis3[0], legend="Line 0", **props) 
l1 = p.line(x, 4 * np.cos(x), color=Viridis3[1], legend="Line 1", **props) 

l1.visible = False # NEW 

l2 = p.line(x, np.tan(x), color=Viridis3[2], legend="Line 2", **props) 

checkbox = CheckboxGroup(labels=["Line 0", "Line 1", "Line 2"], 
         active=[0, 2], width=100) 
checkbox.callback = CustomJS.from_coffeescript(args=dict(l0=l0, l1=l1, l2=l2, checkbox=checkbox), code=""" 
l0.visible = 0 in checkbox.active; 
l1.visible = 1 in checkbox.active; 
l2.visible = 2 in checkbox.active; 
""") 

layout = row(checkbox, p) 
show(layout) 

をしかし、また、これのどれもが必要ではないかもしれませんしてください。便利な機能です

https://bokeh.pydata.org/en/latest/docs/user_guide/interaction/legends.html#userguide-interaction-legends

+0

:ボケは、任意のJSせずに非表示にすることができます/ショー/ミュート異なるグリフインタラクティブな伝説を内蔵しています!私は両方を試してみて、どちらが自分のユースケースでうまくいくかを見てみたいと思います。ありがとうございました! – user4279562

関連する問題