Bar grouping

After trying for what felt like an eternity I can not find out how to do the following with the bar chart.

I have data which is sorted like this:

A B C Label

0 1 2 3 ‘0’

1 1.1 2.1 3.1 ‘1’

2 1.2 2.2 3.2 ‘2’

N X1 X2 X3 ‘N’

What I would like to do now is to have a bar chart with the Labels ‘0’, ‘1’ etc. and for each label three bars with the corresponding heights to column A, B and C. However, with the given grouping options I could not find a solution to get this to work. Do I miss something?

Thanks a lot!

This may be a new feature to be developed. All the current capability is on display in the User's Guide. In particular, here is an example that shows what can be done with grouping:

  http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#grouping

Perhaps you can submit a new feature request on the GitHub issue tracker describing new or more sophisticated labeling options?

Thanks,

Bryan

···

On Oct 15, 2015, at 2:38 AM, [email protected] wrote:

After trying for what felt like an eternity I can not find out how to do the following with the bar chart.
I have data which is sorted like this:

    A B C Label
0 1 2 3 '0'
1 1.1 2.1 3.1 '1'
2 1.2 2.2 3.2 '2'
..
N X1 X2 X3 'N'

What I would like to do now is to have a bar chart with the Labels '0', '1' etc. and for each label three bars with the corresponding heights to column A, B and C. However, with the given grouping options I could not find a solution to get this to work. Do I miss something?

Thanks a lot!

--
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/53454a64-3e00-4861-b247-7d198abf8a51%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

I’ll see if I can get an example working, but if you have some sample data that would make things easier. At least for the new charts, it expects non-pre-aggregated (not pivot table) data. In your case, you are using the columns A, B, C as a categorical variable. Imagine if you stacked those values into a single column. You would this have a second column called variable that contains ‘A’, ‘B’, and ‘C’.

This operation of de-pivoting is something that pandas melt provides, but there will likely be some special case handling of this kind of data in charts in the future. For now, this is how you could produce what you are trying to build:

from bokeh.charts import Bar

from bokeh.plotting import output_file, show

import pandas as pd

data = {

‘A’: [1, 1.1, 1.2],

‘B’: [2, 2.1, 2.2],

‘C’: [3, 3.1, 3.2],

‘label’: [0, 1, 2]

}

df = pd.DataFrame.from_dict(data)

this combines A, B, C into two columns, ‘variable’ containing A, B, C and values

containing the values associated with A, B, and C

df = pd.melt(df, id_vars=‘label’, value_vars=[‘A’, ‘B’, ‘C’])

stack the bars by the new variable

hist = Bar(df, values=‘value’, label=‘label’, stack=‘variable’, legend=True)

output_file(“bar.html”)

show(hist)

``

This produces the following chart:

···

On Thursday, October 15, 2015 at 4:59:18 AM UTC-5, pf wrote:

After trying for what felt like an eternity I can not find out how to do the following with the bar chart.

I have data which is sorted like this:

A B C Label

0 1 2 3 ‘0’

1 1.1 2.1 3.1 ‘1’

2 1.2 2.2 3.2 ‘2’

N X1 X2 X3 ‘N’

What I would like to do now is to have a bar chart with the Labels ‘0’, ‘1’ etc. and for each label three bars with the corresponding heights to column A, B and C. However, with the given grouping options I could not find a solution to get this to work. Do I miss something?

Thanks a lot!