Color Axis Text by Group

I have a categorical variable along one of my plotting axes, and certain levels of the variable belong to different “groups”. Is there a way to color the text displaying each categorical level on my plot by the group that it belongs to? Even if I have to hand construct the color vector outside of the plotting function, that would be fine. As of now, it seems that there’s only an option (using themes) to color text but all text has to be that color.

Example: my x-axis labels are “Protege”, “RAV4”, “Highlander”, “Camry”, “Expedition” and I want to color by the car company, so I want these to be colored “blue”, “red”, “red”, “red”, “green”

I don’t think that’s
currently possible. Feel free to add a feature request on the github issues.

···

On 7/26/16 9:40 AM, Lisa Bramer wrote:

    I have a categorical variable along one of my

plotting axes, and certain levels of the variable belong to
different “groups”. Is there a way to color the text displaying
each categorical level on my plot by the group that it belongs
to? Even if I have to hand construct the color vector outside of
the plotting function, that would be fine. As of now, it seems
that there’s only an option (using themes) to color text but all
text has to be that color.

      Example: my x-axis labels are "Protege", "RAV4",

“Highlander”, “Camry”, “Expedition” and I want to color by the
car company, so I want these to be colored “blue”, “red”,
“red”, “red”, “green”

  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/b5d28236-6ce3-458a-bb8e-bd3b01b8da78%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/b5d28236-6ce3-458a-bb8e-bd3b01b8da78%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)

It's definitely not currently supported. Longer term I'd like to factor out the drawing of tick labels to use the new Label annotation, which would potentially expose an avenue for styling individual tick labels. It's a bit complicated in general, for an interactive system, though. If you have N fixed tick labels it's easy to say which should be what color. But what happens when the plot is panned or zoomed and the set of ticks changes completely?

Anyway, in case it is useful, there is also the option to create a custom extension. The code that draws and formats tick labels in the built-in axis is here:

  https://github.com/bokeh/bokeh/blob/master/bokehjs/src/coffee/models/axes/axis.coffee#L85-L111

If you write a custom subclass CategoricalAxis, you can override and provide a new version of that "_draw_major_labels" method. It would basically be a copy-paste that adds a few limes to apply separate colors to the HTML canvas context before the canvas fillText function is called. Not saying that's trivial, absent some JS experience, but wanted to throw out the possible path in case you do.

Bryan

···

On Aug 4, 2016, at 8:16 AM, Sarah Bird - Continuum <[email protected]> wrote:

I don't think that's currently possible. Feel free to add a feature request on the github issues.

On 7/26/16 9:40 AM, Lisa Bramer wrote:

I have a categorical variable along one of my plotting axes, and certain levels of the variable belong to different "groups". Is there a way to color the text displaying each categorical level on my plot by the group that it belongs to? Even if I have to hand construct the color vector outside of the plotting function, that would be fine. As of now, it seems that there's only an option (using themes) to color text but all text has to be that color.

Example: my x-axis labels are "Protege", "RAV4", "Highlander", "Camry", "Expedition" and I want to color by the car company, so I want these to be colored "blue", "red", "red", "red", "green"
--
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/b5d28236-6ce3-458a-bb8e-bd3b01b8da78%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
Sarah Bird
Developer, Bokeh

--
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/dd64a5c0-8935-0f80-630e-c03fbc5df03a%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.