Bar plot with mutiple categories

Hi,

I’m trying to make a plot à la this one in the docs with pandas dataframes (so I follow this recipe again from the docs).

My script gives me this warning:

Created new window in existing browser session.

1047 [493:529:1122/201630.270760:ERROR:browser_gpu_channel_host_factory.cc(108)] Failed to launch GPU process.

``

But I’ve successfully rendered line graphs with this error popping up.

And the output generated is just an absolutely blank canvas.

I’ve written an MRE that replicates my issue:

import pandas as pd

from bokeh.models import ColumnDataSource

from bokeh.plotting import figure

from bokeh.io import show

data = [

    ["A", "X", 10],

    ["A", "Y", 11],

    ["B", "X", 9],

    ["B", "Y", 12],

    ["C", "X", 8],

    ["C", "Y", 9],

    ]

df = pd.DataFrame(data)

df.columns = [“cat1”, “cat2”, “val”]

grouped = df.groupby((“cat1”, “cat2”))

source = ColumnDataSource(grouped)

p = figure()

p.vbar(x = “cat1_cat2”, top = “val_mean”, source = source, width = 1)

show§

``

Did I miss anything stupid?

Hi,

You are not setting x_range in the call to figure. Categorical ranges are arbitrary user-specified labels. You have to explicitly provide this list of categories as the range, so that Bokeh knows what they are are (perhaps most importantly) what order you want them to be in. There are probably several ways to accomplish this, but here is one:

    import pandas as pd
    from bokeh.models import ColumnDataSource, FactorRange
    from bokeh.plotting import figure
    from bokeh.io import show, output_file

    output_file("foo.html")

    data = [
        ["A", "X", 10],
        ["A", "Y", 11],
        ["B", "X", 9],
        ["B", "Y", 12],
        ["C", "X", 8],
        ["C", "Y", 9],
    ]

    df = pd.DataFrame(data)
    df.columns = ["cat1", "cat2", "val"]

    grouped = df.groupby(("cat1", "cat2"))
    source = ColumnDataSource(grouped)

    p = figure(x_range=FactorRange(*list(grouped.groups)))
    p.vbar(x = "cat1_cat2", top = "val_mean", source = source, width = 1)

    show(p)

Thanks,

Bryan

···

On Nov 22, 2017, at 13:25, Robert <[email protected]> wrote:

Hi,

I'm trying to make a plot à la this one in the docs with pandas dataframes (so I follow this recipe again from the docs).

My script gives me this warning:
Created new window in existing browser session.
1047 [493:529:1122/201630.270760:ERROR:browser_gpu_channel_host_factory.cc(108)] Failed to launch GPU process.

But I've successfully rendered line graphs with this error popping up.

And the output generated is just an absolutely blank canvas.

I've written an MRE that replicates my issue:

import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import show

data = [
        ["A", "X", 10],
        ["A", "Y", 11],
        ["B", "X", 9],
        ["B", "Y", 12],
        ["C", "X", 8],
        ["C", "Y", 9],
        ]

df = pd.DataFrame(data)
df.columns = ["cat1", "cat2", "val"]

grouped = df.groupby(("cat1", "cat2"))

source = ColumnDataSource(grouped)

p = figure()
p.vbar(x = "cat1_cat2", top = "val_mean", source = source, width = 1)

show(p)

Did I miss anything stupid?

--
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/a70588c9-c972-49fd-aa40-0145b5b6e612%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.