☰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

[rbokeh] Custom legend title for programmatically mapped aesthetics

Community Support
Steve_Lianoglou
Steve_Lianoglou

Dear Ryan and rbokeh folk:

Is there a way to name legend items correctly when they are
programmatically set?

For instance, when we generate this figure:

figure(iris) %>%
  ly_points(Sepal.Length, Sepal.Width, color=Species)

The legend generated for the colors of the points is correctly named
"Species", but say that we want to programmatically map the color to
an attribute, and we have something like:

colvar <- 'Species'
figure(iris) %>%
  ly_points(Sepal.Length, Sepal.Width, color=colvar)

The name of the legend items for the colors is "colvar", but I'd still
like it to be "Species"

Any attempt to modify the legend parameter in the `ly_points` function
call complains that it can't be touched since it's automatically
generated, so not sure how to proceed.

Is this supported yet, or?

Thanks,
-steve

···

--
Steve Lianoglou
Bioinformatics Scientist
Cancer Immunology
Genentech

⌁   Link to post
Geoffrey_Gillett
Geoffrey_Gillett

Hi,

I am trying to use box_select with the VBar glyph.
Hover is working with VBar so hit testing has been added, which is encouraging.
But I see no changes in the selected attribute of the ColumnDataSource or any visual changes.

Is selecting VBars possible?

Cheers
Geoff.

⌁   Link to post
birdsarah_continuum
birdsarah_continuum

The upcoming release for Bokeh (0.12.3) has a better legends API.
It’ll probably take a little while to work its way into rBokeh.

···

On 10/4/16 10:02 PM, Steve Lianoglou
wrote:


Dear Ryan and rbokeh folk:
Is there a way to name legend items correctly when they are
programmatically set?
For instance, when we generate this figure:
figure(iris) %>%
ly_points(Sepal.Length, Sepal.Width, color=Species)
The legend generated for the colors of the points is correctly named
"Species", but say that we want to programmatically map the color to
an attribute, and we have something like:
colvar <- 'Species'
figure(iris) %>%
ly_points(Sepal.Length, Sepal.Width, color=colvar)
The name of the legend items for the colors is "colvar", but I'd still
like it to be "Species"
Any attempt to modify the legend parameter in the `ly_points` function
call complains that it can't be touched since it's automatically
generated, so not sure how to proceed.
Is this supported yet, or?
Thanks,
-steve

–
Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)
⌁   Link to post
blutkreislauf
blutkreislauf

Hi Steve, hi all,

did you work out a solution? I am stuck with the same problem, only that I need to have consistent variable->color mappings.
This is easily achieved by defining the mapping and then use ‘color = colvar’, but completely messes up the legend in that
the legend now shows the color strings: “#FFAABB, #112233, …”.
Any help is appreciated!

Best regards,
Stefan

···

On Wednesday, October 5, 2016 at 7:02:23 AM UTC+2, Steve Lianoglou wrote:

Dear Ryan and rbokeh folk:

Is there a way to name legend items correctly when they are

programmatically set?

For instance, when we generate this figure:

figure(iris) %>%

ly_points(Sepal.Length, Sepal.Width, color=Species)

The legend generated for the colors of the points is correctly named

“Species”, but say that we want to programmatically map the color to

an attribute, and we have something like:

colvar ← ‘Species’

figure(iris) %>%

ly_points(Sepal.Length, Sepal.Width, color=colvar)

The name of the legend items for the colors is “colvar”, but I’d still

like it to be “Species”

Any attempt to modify the legend parameter in the ly_points function

call complains that it can’t be touched since it’s automatically

generated, so not sure how to proceed.

Is this supported yet, or?

Thanks,

-steve

–
Steve Lianoglou

Bioinformatics Scientist

Cancer Immunology

Genentech

⌁   Link to post
Tyler_Nickerson
Tyler_Nickerson

Would the CategoricalColorMapper method in the bokeh.models module solve your problem?

You can provide it with a list of your categories and a list of colors to map to those values as such:


map = CategoricalColorMapper(factors = ['species1', 'species2', 'species3'], palette = ['color1', 'color2', 'color3'])

You can then pass the map to a glyph’s color argument in a dictionary specifying the ‘field’ to map to and the ‘transform’ to use.

Using our map variable it might look something like this if we are using a ColumnDataSource and wish to apply our map to the ‘species’ column:


p = figure()

p.circle(x='x', y='y', source=source, color = { 'field': 'species' , 'transform': map})

···

On Fri, Jan 13, 2017 at 5:59 AM, blutkreislauf@gmail.com wrote:

Hi Steve, hi all,

did you work out a solution? I am stuck with the same problem, only that I need to have consistent variable->color mappings.
This is easily achieved by defining the mapping and then use ‘color = colvar’, but completely messes up the legend in that
the legend now shows the color strings: “#FFAABB, #112233, …”.
Any help is appreciated!

Best regards,
Stefan

On Wednesday, October 5, 2016 at 7:02:23 AM UTC+2, Steve Lianoglou wrote:

Dear Ryan and rbokeh folk:

Is there a way to name legend items correctly when they are

programmatically set?

For instance, when we generate this figure:

figure(iris) %>%

ly_points(Sepal.Length, Sepal.Width, color=Species)

The legend generated for the colors of the points is correctly named

“Species”, but say that we want to programmatically map the color to

an attribute, and we have something like:

colvar ← ‘Species’

figure(iris) %>%

ly_points(Sepal.Length, Sepal.Width, color=colvar)

The name of the legend items for the colors is “colvar”, but I’d still

like it to be “Species”

Any attempt to modify the legend parameter in the ly_points function

call complains that it can’t be touched since it’s automatically

generated, so not sure how to proceed.

Is this supported yet, or?

Thanks,

-steve

–
Steve Lianoglou

Bioinformatics Scientist

Cancer Immunology

Genentech

–

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/20a015d1-c992-47ba-a01a-3365f05c8ced%40continuum.io.

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

⌁   Link to post
blutkreislauf
blutkreislauf

That is a nice suggestion, but as far as I know this feature is unfortunately not yet available in rBokeh.

···

On Friday, January 13, 2017 at 6:56:38 PM UTC+1, Tyler Nickerson wrote:

Would the CategoricalColorMapper method in the bokeh.models module solve your problem?

You can provide it with a list of your categories and a list of colors to map to those values as such:

map = CategoricalColorMapper(factors = [‘species1’, ‘species2’, ‘species3’], palette = [‘color1’, ‘color2’, ‘color3’])

You can then pass the map to a glyph’s color argument in a dictionary specifying the ‘field’ to map to and the ‘transform’ to use.

Using our map variable it might look something like this if we are using a ColumnDataSource and wish to apply our map to the ‘species’ column:

p = figure()

p.circle(x=‘x’, y=‘y’, source=source, color = { ‘field’: ‘species’ , ‘transform’: map})

On Fri, Jan 13, 2017 at 5:59 AM, blutkr...@gmail.com wrote:

Hi Steve, hi all,

did you work out a solution? I am stuck with the same problem, only that I need to have consistent variable->color mappings.
This is easily achieved by defining the mapping and then use ‘color = colvar’, but completely messes up the legend in that
the legend now shows the color strings: “#FFAABB, #112233, …”.
Any help is appreciated!

Best regards,
Stefan

On Wednesday, October 5, 2016 at 7:02:23 AM UTC+2, Steve Lianoglou wrote:

Dear Ryan and rbokeh folk:

Is there a way to name legend items correctly when they are

programmatically set?

For instance, when we generate this figure:

figure(iris) %>%

ly_points(Sepal.Length, Sepal.Width, color=Species)

The legend generated for the colors of the points is correctly named

“Species”, but say that we want to programmatically map the color to

an attribute, and we have something like:

colvar ← ‘Species’

figure(iris) %>%

ly_points(Sepal.Length, Sepal.Width, color=colvar)

The name of the legend items for the colors is “colvar”, but I’d still

like it to be “Species”

Any attempt to modify the legend parameter in the ly_points function

call complains that it can’t be touched since it’s automatically

generated, so not sure how to proceed.

Is this supported yet, or?

Thanks,

-steve

–
Steve Lianoglou

Bioinformatics Scientist

Cancer Immunology

Genentech

–

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+un...@continuum.io.

To post to this group, send email to bo...@continuum.io.

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/20a015d1-c992-47ba-a01a-3365f05c8ced%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