2015-12-10 5 views
5

私はいくつかのオブザーバブルのtimeseriesからなるデータセットを持っていますが、bokehを使って時系列の異なるポイントで位相ダイアグラムを見たいと思います。私が知りたいのは、選択されたグリフまたは選択されていないグリフのプロパティを変更する方法です(この場合、選択されていないポイントのアルファ値を減らしたり、選択したグリフの色を変更したい)。bokehで選択/選択されていないグリフのプロパティを設定する方法

以下のコードは、ipythonノートブックに必要なインターフェイスを作成し、users guidehttp://bokeh.pydata.org/en/0.10.0/docs/user_guide/interaction.html#linked-brushingの例に基づいています。私は設定するための任意の明白なオプションを見つけることができないと私は本当にむしろこの1つの事のためのjavascriptを習得する必要はないだろう。

import numpy as np 
from pandas import DataFrame 
from bokeh.plotting import figure, output_notebook, show, gridplot 
from bokeh.models import ColumnDataSource, widgets 

def znzt_ts():#, plot_antisym=False, **kwargs): 
    t = np.arange(1000) 
    Eu = np.sin(t * np.pi/10) + np.random.random(1000) 
    Ez = np.cos(t * np.pi/10) + np.random.random(1000) 
    ts = DataFrame({'t': t, 'Eu': Eu, 'Ez': Ez}) 
    tools = 'box_zoom,pan,reset,save,box_select' 
    source = ColumnDataSource(data=ts) 
    original_source = ColumnDataSource(data=ts) 

    p1 = figure(plot_width=300, plot_height=300, 
       tools=tools) 
    p2 = figure(plot_width=300, plot_height=300, tools=tools,) 
    p1.circle('t', 'Eu', source=source, size=1) 
    p2.circle('Eu', 'Ez', source=source, size=1) 
    return gridplot([[p1, p2]]) 

gp = znzt_ts() 
output_notebook() 
show(gp) 
+0

これはすでに見ましたか? (http://bokeh.pydata.org/en/0.9.3/docs/user_guide/styling.html) – Adam

答えて

3

彼のコメントに掲示linkアダムはこれを行う方法を示します:あなたは、所望の特性を有するグリフにサークルレンダラーのselection_glyphnonselection_glyphを設定する必要があります。

マニュアルでは、p.circle(..., name="mycircle")コールに名前を割り当ててから、renderer = p.select(name="mycircle")を使用してレンダラーにアクセスします。 p.circle(...)関数によって返されたレンダラへの参照を保存することもできます:renderer = p.circle('t', 'Eu', source=source, line_color=None)

あなたはレンダラへの参照を持っていたら、あなたはグリフ割り当てることができます。完全に選択されていないグリフを削除するには

renderer.selection_glyph = Circle(fill_color='firebrick', line_color=None) 
renderer.nonselection_glyph = Circle(fill_color='#1f77b4', fill_alpha=0.1, line_color=None) 

import numpy as np 
from pandas import DataFrame 
from bokeh.plotting import figure, output_notebook, show, gridplot 
from bokeh.models import ColumnDataSource, widgets 
from bokeh.models.glyphs import Circle 

def znzt_ts():#, plot_antisym=False, **kwargs): 
    t = np.arange(1000) 
    Eu = np.sin(t * np.pi/10) + np.random.random(1000) 
    Ez = np.cos(t * np.pi/10) + np.random.random(1000) 
    ts = DataFrame({'t': t, 'Eu': Eu, 'Ez': Ez}) 
    tools = 'box_zoom,pan,reset,save,box_select' 
    source = ColumnDataSource(data=ts) 
    original_source = ColumnDataSource(data=ts) 

    selection_glyph = Circle(fill_color='firebrick', line_color=None) 
    nonselection_glyph = Circle(fill_color='#1f77b4', fill_alpha=0.1, line_color=None) 

    p1 = figure(plot_width=300, plot_height=300, tools=tools) 
    r1 = p1.circle('t', 'Eu', source=source, line_color=None) 
    r1.selection_glyph = selection_glyph 
    r1.nonselection_glyph = nonselection_glyph 


    p2 = figure(plot_width=300, plot_height=300, tools=tools) 
    r2 = p2.circle('Eu', 'Ez', source=source, line_color=None) 
    r2.selection_glyph = selection_glyph 
    r2.nonselection_glyph = nonselection_glyph 
    return gridplot([[p1, p2]]) 

gp = znzt_ts() 
output_notebook() 
show(gp) 
0

を、あなたが使用することができます。

fig = Figure() 
c = fig.circle(x='x', y='y', source=source) 
c.nonselection_glyph.visible = False 
関連する問題