简体   繁体   中英

Can't update CDSView in a bokeh plot

I know that many topics on this subject has already been discussed but i can't really see what's wrong in my code I have a very big amount of data to plot (lines), and i want to highlight some of them (by circle) according to user choice via a select button) I have tried to make my code as the most simple as possible to reflect my problem.

The line is plotted, the circle based on the "by defaut" choice of the select button are plotted, but nothing is updated when selecting another "stupid_label" in my select widget

import pandas as pd
import numpy as np
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models import  ColumnDataSource, CDSView, GroupFilter
from bokeh.models.widgets import Select
from bokeh.layouts import row, column


def update_plot(attr, old, new):
    view.filters[0] = GroupFilter(column_name='stupid_label', group=stupidlabel.value)

def make_plot(fim):

    TOOLS = "save,pan,box_zoom,reset,wheel_zoom"
    p = figure(title="the plot that makes me mad !",plot_width=800, plot_height=400,tools=TOOLS)
    p.line(fim.mydates,fim.myvalues,color='blue')
    return p

def main(): 
    f = {'mydates': [19123, 19124, 19125, 19126,19127,19128,19129,19129,19130], 'myvalues': [34, 41, 12, 7, 27, 40, 32, 11, 1], 'stupid_label': ['POUET', 'POUET','BANZAI','BANZAI','BANZAI', 'YOUPI','YOUPI','POUET','POUET']}
    fim = pd.DataFrame(data=f)
    p = make_plot(fim)   

    u_stupid_label=np.unique(fim.stupid_label)
    stupidlabel = Select(value=u_stupid_label[0],options=list(u_stupid_label))

    src= ColumnDataSource(fim)
    view = CDSView(source=src,filters=[GroupFilter(column_name='stupid_label', group=stupidlabel.value)])
    p.circle('mydates','myvalues',source=src,view=view,color='black')

    stupidlabel.on_change('value', update_plot)

    layout = row(p, stupidlabel) 
    curdoc().add_root(layout)
    curdoc().title = "please.. works !!!"

main()

所有,我最后删除了我的 def main() 和 main(),它可以工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM