如何在散景

时间:2015-12-10 19:56:36

标签: javascript python bokeh

我有一个由几个可观测量的时间序列组成的数据集,我想使用散景来查看时间序列中不同点的相图。我想知道的是如何更改所选或未选定字形的属性(在这种情况下,我希望减少未选择点的alpha值或更改所选点的颜色)。

下面的代码在ipython笔记本中创建了我想要的界面,并基于users guide http://bokeh.pydata.org/en/0.10.0/docs/user_guide/interaction.html#linked-brushing中的示例。我无法找到任何明显的选项,我真的不需要为这一件事学习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)

2 个答案:

答案 0 :(得分:3)

他在评论中发布的link Adam告诉您如何执行此操作:您需要将圆形渲染器的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)

答案 1 :(得分:0)

要完全删除未选择的字形,您可以使用:

fig = Figure()
c = fig.circle(x='x', y='y', source=source)
c.nonselection_glyph.visible = False