Based on a Select widget update a second Select widget, then how to link the latter to a (reactive) plot?

@Marc

Hi Marc,

Thanks so much for taking the time to answer all my questions, and for providing me with a full working example; I see you used Param: do you always go straight to it?

Either way, this will get me started with it! It is very useful to move further into a new area as you call it and see how someone else with a lot if experience thinks; I will read it, break it down, tinker with it, very valuable!

About the use of cmaps specifically, I am still confused.
I initially had your same thougth, because with Matplotlib you use quotes, but with Colorcet you do not. But then I read on the User Guide that:
“The same colormaps are also registered with Matplotlib’s string-based dictionary with the prefix cet_ , making them available by name within various matplotlib functions (e.g. cet_linear_kryw_0_100_c71 , cet_linear_kryw_0_100_c71_r , cet_fire , or cet_fire_r ).”

So, if I try this simpler example with only those Colorcet cmaps, it works, because I use colormap with the decorator. Is there no way to do it with both Matplotlib and Colorcet without using an if - else statement?
cet_only

import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.colors as clr
    import colorcet as cc

    import panel as pn
    pn.extension()

colormap = pn.widgets.Select(name='Colorcet colormap', options= sorted([
    'cet_bgy', 'cet_bkr', 'cet_bgyw', 'cet_bky', 'cet_kbc', 'cet_coolwarm', 
    'cet_blues', 'cet_gwv', 'cet_bmw', 'cet_bjy', 'cet_bmy', 'cet_bwy', 'cet_kgy', 
    'cet_cwr', 'cet_gray', 'cet_dimgray', 'cet_fire', 'kb', 'cet_kg', 'cet_kr',
    'cet_colorwheel', 'cet_isolium', 'cet_rainbow', 'cet_bgy_r', 'cet_bkr_r', 
    'cet_bgyw_r', 'cet_bky_r', 'cet_kbc_r', 'cet_coolwarm_r', 'cet_blues_r', 
    'cet_gwv_r', 'cet_bmw_r', 'cet_bjy_r', 'cet_bmy_r', 'cet_bwy_r', 'cet_kgy_r', 
    'cet_cwr_r', 'cet_gray_r', 'cet_dimgray_r', 'cet_fire_r', 'kb_r', 'cet_kg_r', 
    'cet_kr_r', 'cet_colorwheel_r', 'cet_isolium_r', 'cet_rainbow_r'], 
    key=str.casefold), value='cet_blues') 

selection_widget = pn.Row(colormap)

rndm = np.random.rand(8,8)

def plot(data, colormap):      
    fig = plt.figure()   
    plt.imshow(data, colormap); 
    plt.tight_layout() 
    plt.colorbar()
    plt.close(fig=fig)    
    return fig

@pn.depends(colormap) 
def reactive_plots(colormap):
    return plot(rndm, colormap)

pn.Column(selection_widget, reactive_plots).show() 

So I am still a bit unsure. Perhaps it is just a matter of choosing the wrong object?

By the way, I see you work for Ørsted, which is an interesting connection because I worked for DONG Energy in Stavanger, Norway, in 2012-2013.

1 Like