Search code examples
python-3.xplotbokeh

Update in real time fill_color in Bokeh


I'm trying to update fill_color from a real time hex_tile plot in bokeh 2.3.3 in python 3.8. More specifically, I want to update the max range of the linear_cmap that fill the plot. To update the max value, I've tried to pass a linear mapper to a column in the ColumnDataSource that I'm using. I've also tried to use .update over the figure, and pass the mapper to fill_color:

def update():
    new_data = bin_generate().to_dict(orient='list')
    source.stream(new_data,rollover = 50)
    maper = linear_cmap('counts', 'Viridis256', 0, max(bin_generate().counts))
    f.hex_tile.fill_color=maper
    #f.hex_tile.fill_color={'transform':maper}

data=bin_generate().to_dict(orient='list')
maper = linear_cmap('counts', 'Viridis256', 0, max(bin_generate().counts))

source = ColumnDataSource(data=data)
f = figure(x_range=(-5,5),y_range=(0,6), toolbar_location=None, tools="hover",
         match_aspect=True, background_fill_color='#440154')

f.hex_tile(q="q", r="r",size=0.09, line_color=None, source=source,  
           fill_color=maper)

curdoc().add_root(f)
curdoc().add_periodic_callback(update,100)

How can I update the max value of the cmaper?


Solution

  • i didn't test it out but this could work :

    first, give a name

    hextile = f.hex_tile(q="q", r="r",size=0.09, line_color=None, source=source,  
               fill_color=maper)
    

    in function, add :

    hextile.glyph.fill_color=maper
    

    you should check it out first from here

    also, you should give full code and some data to check it out.