簡體   English   中英

從滑塊更改中回叫,不會在jupyter實驗室的bokeh中更新我的情節?

[英]call back from slider change not updating my plot in bokeh in jupyter lab?

我正在研究多個類別的數據集的Bokeh可視化。 視覺效果的初始部分是類別的甜甜圈圖,顯示每個類別中項目的總數。 我正在嘗試使用RangeSlider根據最小-最大范圍來更新圖表-但圖表不會更新。

字形的輸入源是create_cat_df的輸出-作為熊貓DF返回,然后使用ColumnDataSource.from_df()轉換為CDS。

當運行此代碼時(滑蓋在旁邊),圖表看起來還可以-但是移動滑蓋不會改變任何內容。

還有一個類似的帖子在這里 此處的答案對於將我放到from_dffrom_df -但即使遵循此步驟,我也無法使代碼正常工作。

def create_doc(doc):

    ### INPUT widget
    cat_min_max = RangeSlider(start=0, end=1000, value=[0, 1000], step=1, title="Category min-max items (m)")

    inputs = column(cat_min_max, width=300, height=850)  # in preparation for multiple widgets

    ### Tooltip & tools
    TOOLTIPS_2 = [("Item", "$item")            # a sample
               ]

    hover_2 = HoverTool(tooltips=TOOLTIPS_2, names = ['cat'])
    tools = [hover_2, TapTool(), WheelZoomTool(), PanTool(), ResetTool()] 


    ### Create Figure
    p = figure(plot_width=width, plot_height=height, title="",
        x_axis_type=None, y_axis_type=None,
        x_range=(-420, 420), y_range=(-420, 420), 
        min_border=0, outline_line_color=None,
        background_fill_color="#f0e1d2",
              tools = tools, toolbar_location="left")

    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = None

    # taptool
    url = "https://google.com/"    #dummy URL
    taptool = p.select(type=TapTool)
    taptool.callback = OpenURL(url=url)

    # create cat_source CDS using create_cat_df function (returns pandas df) and 'from_df' method
    cat_source = ColumnDataSource.from_df(create_cat_df(cat_min_max.value[0], cat_min_max.value[1]))

    ## plot category  wedges
    p.annular_wedge('centre_x', 'centre_y', 'inner', 'outer', 'start', 'end', color='color', 
                    alpha='alpha', direction='clock', source=cat_source, name='cat')

    r = row([inputs, p])

    def callback(attr, old, new):
        cat_source.data = ColumnDataSource.from_df(create_cat_df(cat_min_max.value[0], cat_min_max.value[1]))

    cat_min_max.on_change('value', callback)  

    doc.add_root(r)


show(create_doc)

我想讓代碼正常工作並更新圖表。 有更多的字形和不同的數據層可以分層,但是我想讓基礎知識首先起作用。

根據Bokeh文檔 ,當您需要將ColumnDatSource傳遞給p.annular_wedge(source = cat_source)source參數時, ColumnDataSource.from_df()方法將返回字典。

所以代替:

cat_source = ColumnDataSource.from_df(create_cat_df(cat_min_max.value[0], cat_min_max.value[1]))

你應該做:

cat_source = ColumnDataSource(data = ColumnDataSource.from_df(create_cat_df(cat_min_max.value[0], cat_min_max.value[1])))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM