Stacked bar plot - controlling colors

Hi,

I am trying to make a hbar_stack plot for to visualize following properties:

11 entries along y-axis (name1, name2, …) with 15 values for each entry to be plotted along the y-axis as bars.

Each value come from one of 5 categories: [‘A’,‘B’,‘C’,‘D’,‘E’], I want the color of the bar to represent the respective category.

So far I’ve followed the stacked_split example from

https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html

I can plot the data as I’ve intended, but not been able to color the bars. My problem is similar, but instead of having imports from each year, I have imports from different countries wich may not be the same for all fruits. I want the color to represent countries!

I’ve tried looking at the autompg example from the same page as I figured it could have some clues to my problem, but haven’t been able to apply the color handling to hbar_stack.

I am fairly new to Bokeh, but so far I am really enjoying it and I think the documentation is great. Reading older comments on Bokeh, it is clear that someone must have done a good job at improving both documentation and use friendly-ness.

Hi,

If you have a column in your data source that has the categories, then you should be able to do something like:

  color=factor_cmap('colname', palette=list_of_colors, factors=['A','B','C','D','E'])

See e.g. the second example here:

  https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#colors

Bryan

···

On Aug 22, 2018, at 06:05, André <[email protected]> wrote:

Hi,

I am trying to make a hbar_stack plot for to visualize following properties:

11 entries along y-axis (name1, name2, ...) with 15 values for each entry to be plotted along the y-axis as bars.
Each value come from one of 5 categories: ['A','B','C','D','E'], I want the color of the bar to represent the respective category.

So far I've followed the stacked_split example from
https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html

I can plot the data as I've intended, but not been able to color the bars. My problem is similar, but instead of having imports from each year, I have imports from different countries wich may not be the same for all fruits. I want the color to represent countries!

I've tried looking at the autompg example from the same page as I figured it could have some clues to my problem, but haven't been able to apply the color handling to hbar_stack.

I am fairly new to Bokeh, but so far I am really enjoying it and I think the documentation is great. Reading older comments on Bokeh, it is clear that someone must have done a good job at improving both documentation and use friendly-ness.

--
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/d03c6290-8b84-4eeb-bd05-836906a84eac%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Thank you for your reply

I am having trouble applying your suggestion to my plot, as it is a stacked plot and the example only covers a regular bar plot.

When passing data to a stacked bar plot each stack have its own source column of data, so I tried passing a list of column names of columns with factors instead of name of a single column to factor_cmap, but got an error.

···

On Wednesday, August 22, 2018 at 6:34:07 PM UTC+2, Bryan Van de ven wrote:

Hi,

If you have a column in your data source that has the categories, then you should be able to do something like:

    color=factor_cmap('colname', palette=list_of_colors, factors=['A','B','C','D','E'])

See e.g. the second example here:

    [https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#colors](https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#colors)

Bryan

On Aug 22, 2018, at 06:05, André [email protected] wrote:

Hi,

I am trying to make a hbar_stack plot for to visualize following properties:

11 entries along y-axis (name1, name2, …) with 15 values for each entry to be plotted along the y-axis as bars.

Each value come from one of 5 categories: [‘A’,‘B’,‘C’,‘D’,‘E’], I want the color of the bar to represent the respective category.

So far I’ve followed the stacked_split example from

https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html

I can plot the data as I’ve intended, but not been able to color the bars. My problem is similar, but instead of having imports from each year, I have imports from different countries wich may not be the same for all fruits. I want the color to represent countries!

I’ve tried looking at the autompg example from the same page as I figured it could have some clues to my problem, but haven’t been able to apply the color handling to hbar_stack.

I am fairly new to Bokeh, but so far I am really enjoying it and I think the documentation is great. Reading older comments on Bokeh, it is clear that someone must have done a good job at improving both documentation and use friendly-ness.


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/d03c6290-8b84-4eeb-bd05-836906a84eac%40continuum.io.

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

Hi,

The vbar_stack and hbar_stack explicitly do not have separate data sources for the glyphs they create. So I am not really sure what you are doing. At this point, in order for us to be able to help you, you really need to prove a complete, minimal example script that demonstrates the specific task you are having trouble with.

Thanks,

Bryan

···

On Aug 23, 2018, at 00:47, André <[email protected]> wrote:

Thank you for your reply

I am having trouble applying your suggestion to my plot, as it is a stacked plot and the example only covers a regular bar plot.

When passing data to a stacked bar plot each stack have its own source column of data, so I tried passing a list of column names of columns with factors instead of name of a single column to factor_cmap, but got an error.

On Wednesday, August 22, 2018 at 6:34:07 PM UTC+2, Bryan Van de ven wrote:
Hi,

If you have a column in your data source that has the categories, then you should be able to do something like:

        color=factor_cmap('colname', palette=list_of_colors, factors=['A','B','C','D','E'])

See e.g. the second example here:

        https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html#colors

Bryan

> On Aug 22, 2018, at 06:05, André <[email protected]> wrote:
>
> Hi,
>
> I am trying to make a hbar_stack plot for to visualize following properties:
>
> 11 entries along y-axis (name1, name2, ...) with 15 values for each entry to be plotted along the y-axis as bars.
> Each value come from one of 5 categories: ['A','B','C','D','E'], I want the color of the bar to represent the respective category.
>
> So far I've followed the stacked_split example from
> https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html
>
> I can plot the data as I've intended, but not been able to color the bars. My problem is similar, but instead of having imports from each year, I have imports from different countries wich may not be the same for all fruits. I want the color to represent countries!
>
> I've tried looking at the autompg example from the same page as I figured it could have some clues to my problem, but haven't been able to apply the color handling to hbar_stack.
>
> I am fairly new to Bokeh, but so far I am really enjoying it and I think the documentation is great. Reading older comments on Bokeh, it is clear that someone must have done a good job at improving both documentation and use friendly-ness.
>
>
> --
> 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/d03c6290-8b84-4eeb-bd05-836906a84eac%40continuum.io.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout.

--
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/b5b9f3db-9e37-43b5-86a9-078f43237639%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.