Difficulty trying to change color mapper with the use of widgets

Hello there,

I have been trying to switch between two different color mappers of patches with the use of widgets, but even trying to include a static color mapper as a part of a DataColumnSource fails triumphantly.

palettes = [pv_palette, wind_palette]

palette_dict = {‘palettes’:palettes}

palette_source = ColumnDataSource(data = palette_dict)

slider = Slider(title=None, start=0, end=len(date_avg_list)-1, step=1, value=0, show_value=False)

def callback(attr, old, new):

N = slider.value

source.data={‘x’:pv_capacity_merged[‘lons’],

‘y’: pv_capacity_merged[‘lats’],

‘monthly_avg’:pv_capacity_merged[date_avg_list[N]],

‘color_mapper’:pd.Series(516*[LinearColorMapper(palette=palette_source.data[‘palettes’][0],

low=return_source.data[‘lowest’][0],

high=return_source.data[‘highest’][0])])[1]

}

slider.on_change(‘value’, callback)

slider.on_change(‘value’, update_plot2)

p.patches(‘x’, ‘y’, source = source, fill_color={‘field’: ‘monthly_avg’, ‘transform’: ‘color_mapper’},

fill_alpha=0.7, line_color=“white”, line_width=0.5)

The above code should to my understanding load just one color mapper. The 516 is used just to have ColumnDataSource values of equal length.

Any ideas?

Thanks

Hi,

Your main issue is that ColorMappers do not go *in* data source columns. Rather, they represent of transformation *of* a column, and furthermore, this transformation happens in the browser, not in python. You can refer to this example to see the proper usage of LinearColorMapper:

  https://bokeh.pydata.org/en/latest/docs/gallery/unemployment.html

Depending on your use-case, the simpler bokeh.transforms.linear_cmap convenience function might also work. It is used like this, no need to make a LinearColorMapper by hand:

  fill_color=linear_cmap('colname', palette, min, max)

Thanks,

Bryan

···

On Mar 27, 2018, at 06:03, SinniK Al <[email protected]> wrote:

Hello there,

I have been trying to switch between two different color mappers of patches with the use of widgets, but even trying to include a static color mapper as a part of a DataColumnSource fails triumphantly.

palettes = [pv_palette, wind_palette]
palette_dict = {'palettes':palettes}
palette_source = ColumnDataSource(data = palette_dict)

slider = Slider(title=None, start=0, end=len(date_avg_list)-1, step=1, value=0, show_value=False)

def callback(attr, old, new):
    N = slider.value
    source.data={'x':pv_capacity_merged['lons'],
                 'y': pv_capacity_merged['lats'],
                 'monthly_avg':pv_capacity_merged[date_avg_list[N]],
                 'color_mapper':pd.Series(516*[LinearColorMapper(palette=palette_source.data['palettes'][0],
                                         low=return_source.data['lowest'][0],
                                         high=return_source.data['highest'][0])])[1]
                }
    
slider.on_change('value', callback)
slider.on_change('value', update_plot2)
p.patches('x', 'y', source = source, fill_color={'field': 'monthly_avg', 'transform': 'color_mapper'},
          fill_alpha=0.7, line_color="white", line_width=0.5)

The above code should to my understanding load just one color mapper. The 516 is used just to have ColumnDataSource values of equal length.
Any ideas?
Thanks

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/39318729-d828-4361-8909-1a37aed61062%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.