☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Difficulty trying to change color mapper with the use of widgets

Community Support
SinniK_Al
SinniK_Al

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

⌁   Link to post
Bryan
Bryan

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 <sinnikal1983@gmail.com> 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 bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
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\.

⌁   Link to post

End of archived discussion · Replies are disabled