亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用CustomJS更新散景源

如何使用CustomJS更新散景源

牛魔王的故事 2022-08-02 15:50:16
我在嘗試更新散景源時使用“選擇”小部件和自定義JS時遇到了一些問題。在這種情況下,CustomJS是強制性要求,因此不能使用def:函數。下面的代碼返回數據可視化,但它不會刷新,因為我想,JS代碼沒有正確編寫,我沒有辦法調試它(如果有人知道如何,請它確實是我能得到的最好的答案)。主要思想是根據“選擇”微件上選擇的值過濾我的源。任何想法??source = ColumnDataSource(data=dict(    x=gx,    y=gy,    recty=recty,    colors=colors,    filter_info= filter_info))select = Select(title="Option:", value="All", options=["All", "1", "2", "3", "4", "5", "6+"])renderer_source = source# Add the slidercode = """    var value_filter_info = cb_obj.value;    if value_assignments == 'All' {       new_source_data['x'] =  source.data['x'];      new_source_data['y'] =  source.data['y'];      new_source_data['recty'] =  source.data['recty'];      new_source_data['colors'] =  source.data['colors'];    } else {      new_source_data['x'] =  source.data['x'][source.data['filter_info']==value_filter_info];      new_source_data['y'] =  source.data['y'][source.data['filter_info']==value_filter_info];      new_source_data['recty'] =  source.data['recty'][source.data['filter_info']==value_filter_info];      new_source_data['colors'] =  source.data['colors'][source.data['filter_info']==value_filter_info];    }    renderer_source.data= new_source_data;    renderer_source.change.emit();"""callback = CustomJS(args=dict(source=source, renderer_source=renderer_source), code=code)select.js_on_change('value', callback)p = figure(plot_width=1200, plot_height=400, x_range=(0,100), y_range=(0,1000))p.rect(x='x', y='recty',  width=1, height=1, color='colors', source=renderer_source, line_color=None, fill_alpha=1, width_units="data", height_units="data")plot_layout = column(select,p)show(plot_layout)output_notebook()
查看完整描述

1 回答

?
慕工程0101907

TA貢獻1887條經驗 獲得超5個贊

因此,我找到了一個解決方案,可以在美學上,程序上和視覺上得到改善,但至少結果已經顯示出來。


遵循@bigreddot關于索引和覆蓋的建議,我設法編寫了當前的CustomJS代碼:


code = """

    var render=renderer_source.data;

    var data=source.data;

    var data_assignment = data['assignments']; 

    var value_assignments = cb_obj.value; 



    var data_x=data['x'];

    var data_y=data['y'];

    var data_recty=data['recty'];

    var data_colors=data['colors'];


    var render_x=render['x'];

    var render_y=render['y'];

    var render_recty=render['recty'];

    var render_colors=render['colors'];


    var x = [];

    var y = [];

    var recty = [];

    var colors = [];


    render_x=[];

    render_y=[];

    render_recty=[];

    render_colors=[];



    for (var i=0;i<data_assignment.length; i++){


        if (value_assignments == 'All') { 

          x.push(data_x[i]);

          y.push(data_y[i]);

          recty.push(data_recty[i]);

          colors.push(data_colors[i]);

        } else if (data_assignment[i]==value_assignments) {

          x.push(data_x[i]);

          y.push(data_y[i]);

          recty.push(data_recty[i]);

          colors.push(data_colors[i]);


        }

    }


    renderer_source.data['x']=x;

    renderer_source.data['y']=y;

    renderer_source.data['recty']=recty;

    renderer_source.data['colors']=colors;


    renderer_source.change.emit();


"""


查看完整回答
反對 回復 2022-08-02
  • 1 回答
  • 0 關注
  • 86 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號