update ColorBar with callback on dropdown selection

Hi, I have an issue with bokeh and updating the colorbar object. I am trying to update my color bar according to new data plotted via a dropdown callback. The data is getting updated, but the color bar remains scaled to the original data. I have searched the color bar related issues and can’t find a solution. I get this error when I try to just assign a new ColorBar object to the Figure: "AttributeError(“unexpected attribute ‘color_bar’ to Figure.”

Here are the lines I’m using to update on the dropdown selection:

def update_plot(attrname, old, new):

# set variables for new data
data_set = data_select.value
plot_data_name = data_sets.get(data_set)
data = dataframe[plot_data_name]
data_min = data.min()
data_max = data.max()

# create new colors according to changed data set
colors = set_colors(dataframe, data_set)
dataframe['colors'] = colors
new_source = ColumnDataSource(dataframe)
# update plot
plot.title.text = data_set
source.data.update(new_source.data)
color_mapper = LinearColorMapper(palette=Viridis256, low=data_min, high=data_max)
color_bar = ColorBar(color_mapper=color_mapper, \
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')

I guess that I am just trying to overwrite the old ColorBar, but it’s not working, and I am kinda stuck right now. Am I missing some simple way to do this?

Thanks,
Charles

It would be much
easier to help you solve
this with a fully working code example.

At a guess I would suggest.

`p = figure()

      color_mapper = LinearColorMapper()

      color_bar = ColorBar(.....)

      p.add_layout``(co``lor_bar, 'right')`

Then in your update code

`def update_plot(attr, old, new):

          ....

          color_mapper.low = new_min

          color_mapper.high = new_max   

          color_bar.trigger('change')`

But I have no idea if that 'll actually
work. But it’s worth a try.

Or maybe instead of the
trigger. color_``bar.color_mapper = new_color_mapper

···

On 10/13/16 8:43 PM,
wrote:

[email protected]

      Hi, I have an issue with bokeh

and updating the colorbar object. I am trying to update my
color bar according to new data plotted via a dropdown
callback. The data is getting updated, but the color bar
remains scaled to the original data. I have searched the color
bar related issues and can’t find a solution. I get this error
when I try to just assign a new ColorBar object to the Figure:
"AttributeError(“unexpected attribute ‘color_bar’ to Figure.”

      Here are the lines I'm using

to update on the dropdown selection:

      def update_plot(attrname, old,

new):

          # set variables for new data
          data_set = data_select.value
          plot_data_name = data_sets.get(data_set)
          data = dataframe[plot_data_name]
          data_min = data.min()
          data_max = data.max()

# create new colors according to changed data set
colors = set_colors(dataframe, data_set)
dataframe['colors'] = colors
new_source = ColumnDataSource(dataframe)
# update plot
plot.title.text = data_set
source.data.update(new_source.data)
color_mapper = LinearColorMapper(palette=Viridis256, low=data_min, high=data_max)
color_bar = ColorBar(color_mapper=color_mapper, \
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')

      I guess that I am just trying

to overwrite the old ColorBar, but it’s not working, and I am
kinda stuck right now. Am I missing some simple way to do
this?

Thanks,
Charles

  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/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

This works. I guess creating a new color mapper and trying to overwrite the first one was the problem. Updating it is much cleaner. Thank you for your help.

···

On Sunday, October 16, 2016 at 11:41:34 PM UTC-5, Sarah Bird wrote:

      It would be much

easier to help you solve
this with a fully working code example.

At a guess I would suggest.

`p = figure()

      color_mapper = LinearColorMapper()

      color_bar = ColorBar(.....)

      p.add_layout``(co``lor_bar, 'right')`

Then in your update code

`def update_plot(attr, old, new):

          ....

          color_mapper.low = new_min

          color_mapper.high = new_max   

          color_bar.trigger('change')`

But I have no idea if that 'll actually
work. But it’s worth a try.

Or maybe instead of the
trigger. color_``bar.color_mapper = new_color_mapper

  On 10/13/16 8:43 PM, > [email protected] wrote:
      Hi, I have an issue with bokeh

and updating the colorbar object. I am trying to update my
color bar according to new data plotted via a dropdown
callback. The data is getting updated, but the color bar
remains scaled to the original data. I have searched the color
bar related issues and can’t find a solution. I get this error
when I try to just assign a new ColorBar object to the Figure:
"AttributeError(“unexpected attribute ‘color_bar’ to Figure.”

      Here are the lines I'm using

to update on the dropdown selection:

      def update_plot(attrname, old,

new):

          # set variables for new data
          data_set = data_select.value
          plot_data_name = data_sets.get(data_set)
          data = dataframe[plot_data_name]
          data_min = data.min()
          data_max = data.max()

# create new colors according to changed data set
colors = set_colors(dataframe, data_set)
dataframe['colors'] = colors
new_source = ColumnDataSource(dataframe)
# update plot
plot.title.text = data_set
source.data.update(new_source.data)
color_mapper = LinearColorMapper(palette=Viridis256, low=data_min, high=data_max)
color_bar = ColorBar(color_mapper=color_                 mapper, \
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')

      I guess that I am just trying

to overwrite the old ColorBar, but it’s not working, and I am
kinda stuck right now. Am I missing some simple way to do
this?

Thanks,
Charles

  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/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io?utm_medium=email&utm_source=footer).

  For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).


Sarah Bird
Developer, Bokeh

    [
      <img alt="Continuum Analytics" src="https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000" style="width:150px;min-height:30px" height="30px" width="150px">
    ](http://continuum.io)

I’d be very interes ted to see a code snippet of what actually worked
for you in the end. Was the color_bar.trigger necessary?

···

On 10/17/16 10:03 AM,
wrote:

[email protected]

    This works. I guess creating a new color mapper and

trying to overwrite the first one was the problem. Updating it
is much cleaner. Thank you for your help.

    On Sunday, October 16, 2016 at 11:41:34 PM UTC-5, Sarah Bird

wrote:

              It would be

much easier to help you
solve this with a fully working code example.

At a guess
I would suggest.

`p = figure()

              color_mapper = LinearColorMapper()

              color_bar = ColorBar(.....)

              p.add_layout``(co``lor_bar, 'right')`
                        Then in your

update code

`def update_plot(attr, old, new):

                  ....

                  color_mapper.low = new_min

                  color_mapper.high = new_max   

                  color_bar.trigger('change')`
                                      But I

have no idea if that 'll
actually work. But it’s worth
a try.

Or maybe instead
of the trigger. color_`` bar.color_mapper = new_color_mapper

On 10/13/16 8:43 PM, [email protected]
wrote:

              Hi, I have an issue with bokeh and updating the

colorbar object. I am trying to update my color bar
according to new data plotted via a dropdown callback.
The data is getting updated, but the color bar remains
scaled to the original data. I have searched the color
bar related issues and can’t find a solution. I get
this error when I try to just assign a new ColorBar
object to the Figure: "AttributeError(“unexpected
attribute ‘color_bar’ to Figure.”

              Here are the lines I'm using to update on the

dropdown selection:

def update_plot(attrname, old, new):

                  # set variables for new data
                  data_set = data_select.value
                  plot_data_name = data_sets.get(data_set)
                  data = dataframe[plot_data_name]
                  data_min = data.min()
                  data_max = data.max()

# create new colors according to changed data set
colors = set_colors(dataframe, data_set)
dataframe['colors'] = colors
new_source = ColumnDataSource(dataframe)
# update plot
plot.title.text = data_set
source.data.update(new_source.data)
color_mapper = LinearColorMapper(palette=Viridis256, low=data_min, high=data_max)
color_bar = ColorBar(color_mapper=color_                 mapper, \
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')

      I guess that I am just trying

to overwrite the old ColorBar, but it’s not working, and I am
kinda stuck right now. Am I missing some simple way to do
this?

      Thanks,

Charles

  -- 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/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout
.

Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000)
    ](http://continuum.io)

– 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/bbae210c-7649-48d7-a5d4-82e30c472dc1%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sarah Bird
Developer, Bokeh



Ok, here ya go. Actually, the color_bar.trigger wasn’t necessary. Again, thanks for your help!

plot_data.py (4.06 KB)

···

On Monday, October 17, 2016 at 2:08:16 PM UTC-5, Sarah Bird wrote:

I’d be very interes ted to see a code snippet of what actually worked
for you in the end. Was the color_bar.trigger necessary?

  On 10/17/16 10:03 AM, > [email protected] wrote:
    This works. I guess creating a new color mapper and

trying to overwrite the first one was the problem. Updating it
is much cleaner. Thank you for your help.

    On Sunday, October 16, 2016 at 11:41:34 PM UTC-5, Sarah Bird > > wrote:
              It would be

much easier to help you
solve this with a fully working code example.

At a guess
I would suggest.

`p = figure()

              color_mapper = LinearColorMapper()

              color_bar = ColorBar(.....)

              p.add_layout``(co``lor_bar, 'right')`
                        Then in your

update code

`def update_plot(attr, old, new):

                  ....

                  color_mapper.low = new_min

                  color_mapper.high = new_max   

                  color_bar.trigger('change')`
                                      But I

have no idea if that 'll
actually work. But it’s worth
a try.

Or maybe instead
of the trigger. color_`` bar.color_mapper = new_color_mapper

On 10/13/16 8:43 PM, [email protected] > > > wrote:

              Hi, I have an issue with bokeh and updating the

colorbar object. I am trying to update my color bar
according to new data plotted via a dropdown callback.
The data is getting updated, but the color bar remains
scaled to the original data. I have searched the color
bar related issues and can’t find a solution. I get
this error when I try to just assign a new ColorBar
object to the Figure: "AttributeError(“unexpected
attribute ‘color_bar’ to Figure.”

              Here are the lines I'm using to update on the

dropdown selection:

def update_plot(attrname, old, new):

                  # set variables for new data
                  data_set = data_select.value
                  plot_data_name = data_sets.get(data_set)
                  data = dataframe[plot_data_name]
                  data_min = data.min()
                  data_max = data.max()

# create new colors according to changed data set
colors = set_colors(dataframe, data_set)
dataframe['colors'] = colors
new_source = ColumnDataSource(dataframe)
# update plot
plot.title.text = data_set
source.data.update(new_source.data)
color_mapper = LinearColorMapper(palette=Viridis256, low=data_min, high=data_max)
color_bar = ColorBar(color_mapper=color_                 mapper, \
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')

      I guess that I am just trying

to overwrite the old ColorBar, but it’s not working, and I am
kinda stuck right now. Am I missing some simple way to do
this?

      Thanks,

Charles

  -- 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/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics|150x30](upload://9hdBzR8dQvRszNSA9TpUn91YQlq.png)
    ](http://continuum.io)

– 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/bbae210c-7649-48d7-a5d4-82e30c472dc1%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout

.

Sarah Bird
Developer, Bokeh


Continuum Analytics

Thanks very much for
sharing - it’s much appreciated.

···

On 10/17/16 1:49 PM,
wrote:

[email protected]

    Ok, here ya go. Actually, the color_bar.trigger

wasn’t necessary. Again, thanks for your help!

    On Monday, October 17, 2016 at 2:08:16 PM UTC-5, Sarah Bird

wrote:

I’d be very interes ted to see a code snippet of
what actually worked for you in the end. Was the
color_bar.trigger necessary?

On 10/17/16 10:03 AM, [email protected]
wrote:

            This works. I guess creating a new color

mapper and trying to overwrite the first one was the
problem. Updating it is much cleaner. Thank you for your
help.

            On Sunday, October 16, 2016 at 11:41:34 PM UTC-5, Sarah

Bird wrote:

                      It

would be much easier to help you solve this with a fully working code example.

At a guess I would
suggest.

`p = figure()

                      color_mapper = LinearColorMapper()

                      color_bar = ColorBar(.....)

                      p.add_layout``(co``                          lor_bar,

‘right’)`

                                Then in your

update code

` def update_plot(attr, old,
new):

                          ....

                          color_mapper.low = new_min

                          color_mapper.high = new_max   

                          color_bar.trigger('change')`
                                              But

I have no idea if that 'll actually
work. But it’s worth a try.

                                            Or

maybe
instead of the
trigger. color_`` bar.color_mapper = new_color_mapper

On 10/13/16 8:43 PM, [email protected] wrote:

                      Hi, I have an issue with bokeh and updating

the colorbar object. I am trying to update my
color bar according to new data plotted via a
dropdown callback. The data is getting
updated, but the color bar remains scaled to
the original data. I have searched the color
bar related issues and can’t find a solution.
I get this error when I try to just assign a
new ColorBar object to the Figure:
"AttributeError(“unexpected attribute
‘color_bar’ to Figure.”

                      Here are the lines I'm using to update on the

dropdown selection:

def update_plot(attrname, old, new):

                          # set variables for new data
                          data_set = data_select.value
                          plot_data_name = data_sets.get(data_set)
                          data = dataframe[plot_data_name]
                          data_min = data.min()
                          data_max = data.max()

# create new colors according to changed data set
colors = set_colors(dataframe, data_set)
dataframe['colors'] = colors
new_source = ColumnDataSource(dataframe)
# update plot
plot.title.text = data_set
source.data.update(new_source.data)
color_mapper = LinearColorMapper(palette=Viridis256, low=data_min, high=data_max)
color_bar = ColorBar(color_mapper=color_                 mapper, \
label_standoff=12, border_line_color=None, location=(0,0))
plot.add_layout(color_bar, 'right')

      I guess that I am just trying

to overwrite the old ColorBar, but it’s not working, and I am
kinda stuck right now. Am I missing some simple way to do
this?

      Thanks,

Charles

  -- 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/2abbd4a4-9542-440e-95a6-91fabd880969%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](upload://9hdBzR8dQvRszNSA9TpUn91YQlq.png)
    ](http://continuum.io)

– 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/bbae210c-7649-48d7-a5d4-82e30c472dc1%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout

.

Sarah Bird
Developer, Bokeh


Continuum Analytics

– 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/6292b404-35e0-4515-b606-dbd663fdcc2c%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sarah Bird
Developer, Bokeh