New to Bokeh from matplotlib, need help with annotated horizontal group bar charts

Hi,

I’m new to Bokeh from matplotlib (actually I’m totally new to matplotlib and Python as well), so I understand that I need to do a lot of reading before I can pick up the speed.

Meanwhile, I’m wondering if it is possible to do this at all with Bokeh?

Full code at http://stackoverflow.com/a/35654997/2125837, re-posted below:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns sns.set_style("white") #for aesthetic purpose only

# fake data
df = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),
                   'B': np.random.choice(['one', 'two', 'three'], 100),
                   'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),
                   'D': np.random.randint(-10,11,100),
                   'E': np.random.randn(100)})

p = pd.pivot_table(df, index=['A','B'], columns='C', values='D')
e = pd.pivot_table(df, index=['A','B'], columns='C', values='E')

ax = p.plot(kind='barh', xerr=e, width=0.85)

for r in ax.patches:
    if r.get_x() < 0: # it it's a negative bar
        ax.text(0.25, # set label on the opposite side
                r.get_y() + r.get_height()/5., # y
                "{:" ">7.1f}%".format(r.get_x()*100), # text
                bbox={"facecolor":"red",
                      "alpha":0.5,
                      "pad":1},
                fontsize=10, family="monospace", zorder=10)
    else:
        ax.text(-1.5, # set label on the opposite side
                r.get_y() + r.get_height()/5., # y
                "{:" ">6.1f}%".format(r.get_width()*100),
                bbox={"facecolor":"green",
                      "alpha":0.5,
                      "pad":1},
                fontsize=10, family="monospace", zorder=10)
plt.tight_layout()

Thanks

Bokeh can definitely re-create this plot. Currently, positioning of things with "categorical coordinates" is a little clunky, and we hope to make it better soon, but it's still quite possible. You can see an example of positioning quads and test with categorial coordinates here

  http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html

There is also a Span annotation to add lines like the vertical dotted one in your plot:

  http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans

Thanks,

Bryan

···

On Mar 4, 2016, at 9:39 AM, Tong Sun <[email protected]> wrote:

Hi,

I'm new to Bokeh from matplotlib (actually I'm totally new to matplotlib and Python as well), so I understand that I need to do a lot of reading before I can pick up the speed.

Meanwhile, I'm wondering if it is possible to do this at all with Bokeh?

Full code at python - Pandas Bar plot, how to annotate grouped horizontal bar charts - Stack Overflow, re-posted below:

import numpy as
np

import matplotlib.pyplot as
plt

import pandas as
pd

import seaborn as
sns
sns
.set_style("white") #for aesthetic purpose only

# fake data

df
= pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),

'B': np.random.choice(['one', 'two', 'three'], 100),

'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),

'D': np.random.randint(-10,11,100),

'E': np.random.randn(100)})

p
= pd.pivot_table(df, index=['A','B'], columns='C', values='D')

e
= pd.pivot_table(df, index=['A','B'], columns='C', values='E')

ax
= p.plot(kind='barh', xerr=e, width=0.85)

for r in ax.patches:

if r.get_x() < 0: # it it's a negative bar

        ax
.text(0.25, # set label on the opposite side

                r
.get_y() + r.get_height()/5., # y

"{:" ">7.1f}%".format(r.get_x()*100), # text

                bbox
={"facecolor":"red",

"alpha":0.5,

"pad":1},

                fontsize
=10, family="monospace", zorder=10)

else:

        ax
.text(-1.5, # set label on the opposite side

                r
.get_y() + r.get_height()/5., # y

"{:" ">6.1f}%".format(r.get_width()*100),

                bbox
={"facecolor":"green",

"alpha":0.5,

"pad":1},

                fontsize
=10, family="monospace", zorder=10)

plt
.tight_layout()

Thanks

--
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/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the reply Bryan.

I’ll try my best to understand what you’ve referenced, but honestly, it’d be miles for me to reach there, as I’m totally new to all of these.

OK, the situation is that positioning of things with “categorical coordinates” is a little clunky currently. Now, how about putting those values as tooltips instead? As for the vertical dotted line, I can surely live without it. “Getting the values out” is most important to me.

If the answer is yes, could you show me the code to put tooltips in the horizontal group bar charts please?

Once again, the code to generate the data is:

···
df = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),
                   'B': np.random.choice(['one', 'two', 'three'], 100),
                   'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),
                   'D': np.random.randint(-10,11,100),
                   'E': np.random.randn(100)})

p = pd.pivot_table(df, index=['A','B'], columns='C', values='D')
e = pd.pivot_table(df, index=['A','B'], columns='C', values='E')

Thanks

On Fri, Mar 4, 2016 at 10:51 AM, Bryan Van de Ven [email protected] wrote:

Bokeh can definitely re-create this plot. Currently, positioning of things with “categorical coordinates” is a little clunky, and we hope to make it better soon, but it’s still quite possible. You can see an example of positioning quads and test with categorial coordinates here

    [http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html](http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html)

There is also a Span annotation to add lines like the vertical dotted one in your plot:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans)

Thanks,

Bryan

On Mar 4, 2016, at 9:39 AM, Tong Sun [email protected] wrote:

Hi,

I’m new to Bokeh from matplotlib (actually I’m totally new to matplotlib and Python as well), so I understand that I need to do a lot of reading before I can pick up the speed.

Meanwhile, I’m wondering if it is possible to do this at all with Bokeh?

Full code at http://stackoverflow.com/a/35654997/2125837, re-posted below:

import numpy as

np

import matplotlib.pyplot as

plt

import pandas as

pd

import seaborn as

sns

sns

.set_style(“white”) #for aesthetic purpose only

fake data

df

= pd.DataFrame({‘A’: np.random.choice([‘foo’, ‘bar’], 100),

‘B’: np.random.choice([‘one’, ‘two’, ‘three’], 100),

‘C’: np.random.choice([‘I1’, ‘I2’, ‘I3’, ‘I4’], 100),

‘D’: np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

p

= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’, values=‘D’)

e

= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’, values=‘E’)

ax

= p.plot(kind=‘barh’, xerr=e, width=0.85)

for r in ax.patches:

if r.get_x() < 0: # it it’s a negative bar

    ax

.text(0.25, # set label on the opposite side

            r

.get_y() + r.get_height()/5., # y

“{:” “>7.1f}%”.format(r.get_x()*100), # text

            bbox

={“facecolor”:“red”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”, zorder=10)

else:

    ax

.text(-1.5, # set label on the opposite side

            r

.get_y() + r.get_height()/5., # y

“{:” “>6.1f}%”.format(r.get_width()*100),

            bbox

={“facecolor”:“green”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”, zorder=10)

plt

.tight_layout()

Thanks

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/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io.

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

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe.

To unsubscribe from this group and all its topics, 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/F4350A6E-3C4B-4800-BE41-140D0D6EBA56%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Tong,

It's probably best if you start with the User Guide section on hover tooltips, and the smaller examples there:
  
  http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool

And come back with specific questions based on that.

Bryan

···

On Mar 4, 2016, at 10:10 AM, Tong Sun <[email protected]> wrote:

Thanks for the reply Bryan.

I'll try my best to understand what you've referenced, but honestly, it'd be miles for me to reach there, as I'm totally new to all of these.

OK, the situation is that positioning of things with "categorical coordinates" is a little clunky currently. Now, how about putting those values as tooltips instead? As for the vertical dotted line, I can surely live without it. "Getting the values out" is most important to me.

If the answer is yes, could you show me the code to put tooltips in the horizontal group bar charts please?

Once again, the code to generate the data is:
df = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),

'B': np.random.choice(['one', 'two', 'three'], 100),

'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),

'D': np.random.randint(-10,11,100),

'E': np.random.randn(100)})

p
= pd.pivot_table(df, index=['A','B'], columns='C', values='D')

e
= pd.pivot_table(df, index=['A','B'], columns='C', values='E')

Thanks

On Fri, Mar 4, 2016 at 10:51 AM, Bryan Van de Ven <[email protected]> wrote:
Bokeh can definitely re-create this plot. Currently, positioning of things with "categorical coordinates" is a little clunky, and we hope to make it better soon, but it's still quite possible. You can see an example of positioning quads and test with categorial coordinates here

        http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html

There is also a Span annotation to add lines like the vertical dotted one in your plot:

        http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans

Thanks,

Bryan

> On Mar 4, 2016, at 9:39 AM, Tong Sun <[email protected]> wrote:
>
> Hi,
>
> I'm new to Bokeh from matplotlib (actually I'm totally new to matplotlib and Python as well), so I understand that I need to do a lot of reading before I can pick up the speed.
>
> Meanwhile, I'm wondering if it is possible to do this at all with Bokeh?
>
>
>
>
> Full code at python - Pandas Bar plot, how to annotate grouped horizontal bar charts - Stack Overflow, re-posted below:
>
>
> import numpy as
> np
>
> import matplotlib.pyplot as
> plt
>
> import pandas as
> pd
>
> import seaborn as
> sns
> sns
> .set_style("white") #for aesthetic purpose only
>
>
>
> # fake data
>
> df
> = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),
>
>
> 'B': np.random.choice(['one', 'two', 'three'], 100),
>
>
> 'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),
>
>
> 'D': np.random.randint(-10,11,100),
>
>
> 'E': np.random.randn(100)})
>
>
> p
> = pd.pivot_table(df, index=['A','B'], columns='C', values='D')
>
> e
> = pd.pivot_table(df, index=['A','B'], columns='C', values='E')
>
>
> ax
> = p.plot(kind='barh', xerr=e, width=0.85)
>
>
>
> for r in ax.patches:
>
>
> if r.get_x() < 0: # it it's a negative bar
>
> ax
> .text(0.25, # set label on the opposite side
>
> r
> .get_y() + r.get_height()/5., # y
>
>
> "{:" ">7.1f}%".format(r.get_x()*100), # text
>
> bbox
> ={"facecolor":"red",
>
>
> "alpha":0.5,
>
>
> "pad":1},
>
> fontsize
> =10, family="monospace", zorder=10)
>
>
> else:
>
> ax
> .text(-1.5, # set label on the opposite side
>
> r
> .get_y() + r.get_height()/5., # y
>
>
> "{:" ">6.1f}%".format(r.get_width()*100),
>
> bbox
> ={"facecolor":"green",
>
>
> "alpha":0.5,
>
>
> "pad":1},
>
> fontsize
> =10, family="monospace", zorder=10)
>
> plt
> .tight_layout()
>
> Thanks
>
>
>
> --
> 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/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to a topic in the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe\.
To unsubscribe from this group and all its topics, 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/F4350A6E-3C4B-4800-BE41-140D0D6EBA56%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/CAMmz1OdiaV4f5dcOYCZQK7z5q0jjHUBGXNC0EX1d18Ch0TZDSg%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Sure.

Thanks for the link to the hover tooltips.

Now, How to produce a horizontal (grouped) bar? I checked

http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bar

but didn’t find a way to switch the bar to be horizontal.

thanks

···

On Fri, Mar 4, 2016 at 11:17 AM, Bryan Van de Ven [email protected] wrote:

Hi Tong,

It’s probably best if you start with the User Guide section on hover tooltips, and the smaller examples there:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool](http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool)

And come back with specific questions based on that.

Bryan

On Mar 4, 2016, at 10:10 AM, Tong Sun [email protected] wrote:

Thanks for the reply Bryan.

I’ll try my best to understand what you’ve referenced, but honestly, it’d be miles for me to reach there, as I’m totally new to all of these.

OK, the situation is that positioning of things with “categorical coordinates” is a little clunky currently. Now, how about putting those values as tooltips instead? As for the vertical dotted line, I can surely live without it. “Getting the values out” is most important to me.

If the answer is yes, could you show me the code to put tooltips in the horizontal group bar charts please?

Once again, the code to generate the data is:

df = pd.DataFrame({‘A’: np.random.choice([‘foo’, ‘bar’], 100),

‘B’: np.random.choice([‘one’, ‘two’, ‘three’], 100),

‘C’: np.random.choice([‘I1’, ‘I2’, ‘I3’, ‘I4’], 100),

‘D’: np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

p

= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’, values=‘D’)

e

= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’, values=‘E’)

Thanks

On Fri, Mar 4, 2016 at 10:51 AM, Bryan Van de Ven [email protected] wrote:

Bokeh can definitely re-create this plot. Currently, positioning of things with “categorical coordinates” is a little clunky, and we hope to make it better soon, but it’s still quite possible. You can see an example of positioning quads and test with categorial coordinates here

    [http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html](http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html)

There is also a Span annotation to add lines like the vertical dotted one in your plot:

    [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans)

Thanks,

Bryan

On Mar 4, 2016, at 9:39 AM, Tong Sun [email protected] wrote:

Hi,

I’m new to Bokeh from matplotlib (actually I’m totally new to matplotlib and Python as well), so I understand that I need to do a lot of reading before I can pick up the speed.

Meanwhile, I’m wondering if it is possible to do this at all with Bokeh?

Full code at http://stackoverflow.com/a/35654997/2125837, re-posted below:

import numpy as

np

import matplotlib.pyplot as

plt

import pandas as

pd

import seaborn as

sns

sns

.set_style(“white”) #for aesthetic purpose only

fake data

df

= pd.DataFrame({‘A’: np.random.choice([‘foo’, ‘bar’], 100),

‘B’: np.random.choice([‘one’, ‘two’, ‘three’], 100),

‘C’: np.random.choice([‘I1’, ‘I2’, ‘I3’, ‘I4’], 100),

‘D’: np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

p

= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’, values=‘D’)

e

= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’, values=‘E’)

ax

= p.plot(kind=‘barh’, xerr=e, width=0.85)

for r in ax.patches:

if r.get_x() < 0: # it it’s a negative bar

    ax

.text(0.25, # set label on the opposite side

            r

.get_y() + r.get_height()/5., # y

“{:” “>7.1f}%”.format(r.get_x()*100), # text

            bbox

={“facecolor”:“red”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”, zorder=10)

else:

    ax

.text(-1.5, # set label on the opposite side

            r

.get_y() + r.get_height()/5., # y

“{:” “>6.1f}%”.format(r.get_width()*100),

            bbox

={“facecolor”:“green”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”, zorder=10)

plt

.tight_layout()

Thanks

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/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io.

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

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe.

To unsubscribe from this group and all its topics, 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/F4350A6E-3C4B-4800-BE41-140D0D6EBA56%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/CAMmz1OdiaV4f5dcOYCZQK7z5q0jjHUBGXNC0EX1d18Ch0TZDSg%40mail.gmail.com.

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

You received this message because you are subscribed to a topic in the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe.

To unsubscribe from this group and all its topics, 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/1C593E60-2BD3-4A08-AEE8-52ED6B857FC6%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Sure.

Thanks for the link to the hover tooltips.

Now, How to produce a horizontal (grouped) bar? I checked
http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bar
but didn't find a way to switch the bar to be horizontal.

Moreover, I was having problem putting my data even in a normal bar:

import numpy as np
import pandas as pd

from bokeh.charts import Bar, show, output_file

df = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),
                   'B': np.random.choice(['one', 'two', 'three'], 100),
                   'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),
                   'D': np.random.randint(-10,11,100),
                   'E': np.random.randn(100)})

p = pd.pivot_table(df, index=['A','B'], columns='C', values='D')
e = pd.pivot_table(df, index=['A','B'], columns='C', values='E')

p

TOOLS = 'crosshair,hover'

pc = Bar(p, tools=TOOLS)

output_file("bar.html", title="Bokeh Group Horizontal Bar")

show(pc)

The code error out at the step of "pc = Bar" with an error that I don't
understand.

···

On Fri, Mar 4, 2016 at 11:33 AM, Tong Sun <[email protected]> wrote:

thanks

On Fri, Mar 4, 2016 at 11:17 AM, Bryan Van de Ven <[email protected]> > wrote:

Hi Tong,

It's probably best if you start with the User Guide section on hover
tooltips, and the smaller examples there:

http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool

And come back with specific questions based on that.

Bryan

> On Mar 4, 2016, at 10:10 AM, Tong Sun <[email protected]> wrote:
>
> Thanks for the reply Bryan.
>
> I'll try my best to understand what you've referenced, but honestly,
it'd be miles for me to reach there, as I'm totally new to all of these.
>
> OK, the situation is that positioning of things with "categorical
coordinates" is a little clunky currently. Now, how about putting those
values as tooltips instead? As for the vertical dotted line, I can surely
live without it. "Getting the values out" is most important to me.
>
> If the answer is yes, could you show me the code to put tooltips in the
horizontal group bar charts please?
>
> Once again, the code to generate the data is:
> df = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),
>
>
> 'B': np.random.choice(['one', 'two', 'three'], 100),
>
>
> 'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),
>
>
> 'D': np.random.randint(-10,11,100),
>
>
> 'E': np.random.randn(100)})
>
>
> p
> = pd.pivot_table(df, index=['A','B'], columns='C', values='D')
>
> e
> = pd.pivot_table(df, index=['A','B'], columns='C', values='E')
>
> Thanks
>
> On Fri, Mar 4, 2016 at 10:51 AM, Bryan Van de Ven <[email protected]> >> wrote:
> Bokeh can definitely re-create this plot. Currently, positioning of
things with "categorical coordinates" is a little clunky, and we hope to
make it better soon, but it's still quite possible. You can see an example
of positioning quads and test with categorial coordinates here
>
> http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html
>
>
> There is also a Span annotation to add lines like the vertical dotted
one in your plot:
>
>
http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans
>
> Thanks,
>
> Bryan
>
> > On Mar 4, 2016, at 9:39 AM, Tong Sun <[email protected]> wrote:
> >
> > Hi,
> >
> > I'm new to Bokeh from matplotlib (actually I'm totally new to
matplotlib and Python as well), so I understand that I need to do a lot of
reading before I can pick up the speed.
> >
> > Meanwhile, I'm wondering if it is possible to do this at all with
Bokeh?
> >
> >
> >
> >
> > Full code at python - Pandas Bar plot, how to annotate grouped horizontal bar charts - Stack Overflow, re-posted
below:
> >
> >
> > import numpy as
> > np
> >
> > import matplotlib.pyplot as
> > plt
> >
> > import pandas as
> > pd
> >
> > import seaborn as
> > sns
> > sns
> > .set_style("white") #for aesthetic purpose only
> >
> >
> >
> > # fake data
> >
> > df
> > = pd.DataFrame({'A': np.random.choice(['foo', 'bar'], 100),
> >
> >
> > 'B': np.random.choice(['one', 'two', 'three'], 100),
> >
> >
> > 'C': np.random.choice(['I1', 'I2', 'I3', 'I4'], 100),
> >
> >
> > 'D': np.random.randint(-10,11,100),
> >
> >
> > 'E': np.random.randn(100)})
> >
> >
> > p
> > = pd.pivot_table(df, index=['A','B'], columns='C', values='D')
> >
> > e
> > = pd.pivot_table(df, index=['A','B'], columns='C', values='E')
> >
> >
> > ax
> > = p.plot(kind='barh', xerr=e, width=0.85)
> >
> >
> >
> > for r in ax.patches:
> >
> >
> > if r.get_x() < 0: # it it's a negative bar
> >
> > ax
> > .text(0.25, # set label on the opposite side
> >
> > r
> > .get_y() + r.get_height()/5., # y
> >
> >
> > "{:" ">7.1f}%".format(r.get_x()*100), # text
> >
> > bbox
> > ={"facecolor":"red",
> >
> >
> > "alpha":0.5,
> >
> >
> > "pad":1},
> >
> > fontsize
> > =10, family="monospace", zorder=10)
> >
> >
> > else:
> >
> > ax
> > .text(-1.5, # set label on the opposite side
> >
> > r
> > .get_y() + r.get_height()/5., # y
> >
> >
> > "{:" ">6.1f}%".format(r.get_width()*100),
> >
> > bbox
> > ={"facecolor":"green",
> >
> >
> > "alpha":0.5,
> >
> >
> > "pad":1},
> >
> > fontsize
> > =10, family="monospace", zorder=10)
> >
> > plt
> > .tight_layout()
> >
> > Thanks
> >
> >
> >
> > --
> > 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/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io
.
> > For more options, visit
https://groups.google.com/a/continuum.io/d/optout\.
>
> --
> You received this message because you are subscribed to a topic in the
Google Groups "Bokeh Discussion - Public" group.
> To unsubscribe from this topic, visit
https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe
.
> To unsubscribe from this group and all its topics, 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/F4350A6E-3C4B-4800-BE41-140D0D6EBA56%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/CAMmz1OdiaV4f5dcOYCZQK7z5q0jjHUBGXNC0EX1d18Ch0TZDSg%40mail.gmail.com
.
> For more options, visit
https://groups.google.com/a/continuum.io/d/optout\.

--
You received this message because you are subscribed to a topic in the
Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this topic, visit
https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe
.
To unsubscribe from this group and all its topics, 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/1C593E60-2BD3-4A08-AEE8-52ED6B857FC6%40continuum.io
.
For more options, visit https://groups.google.com/a/continuum.io/d/optout
.

There isn’t a horizontal Bar Chart at the moment.

···

On 3/4/16 8:33 AM, Tong Sun wrote:

Sure.

Thanks for the link to the hover
tooltips.

Now, How to produce a horizontal (grouped) bar? I
checked

http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bar

but didn’t find a way to switch the bar to be horizontal.

thanks

      On Fri, Mar 4, 2016 at 11:17 AM, Bryan

Van de Ven [email protected]
wrote:

Hi Tong,

        It's probably best if you start with the User Guide section

on hover tooltips, and the smaller examples there:

                [http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool](http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool)



        And come back with specific questions based on that.



        Bryan


            > On Mar 4, 2016, at 10:10 AM, Tong Sun <                >

wrote:

Thanks for the reply Bryan.

I’ll try my best to understand what you’ve
referenced, but honestly, it’d be miles for me to reach
there, as I’m totally new to all of these.

OK, the situation is that positioning of things
with “categorical coordinates” is a little clunky
currently. Now, how about putting those values as
tooltips instead? As for the vertical dotted line, I can
surely live without it. “Getting the values out” is most
important to me.

If the answer is yes, could you show me the code to
put tooltips in the horizontal group bar charts please?

Once again, the code to generate the data is:
df = pd.DataFrame({‘A’: np.random.choice([‘foo’,
‘bar’], 100),

‘B’: np.random.choice([‘one’, ‘two’, ‘three’],
100),

‘C’: np.random.choice([‘I1’, ‘I2’, ‘I3’, ‘I4’],
100),

‘D’: np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

p
= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’,
values=‘D’)

e
= pd.pivot_table(df, index=[‘A’,‘B’], columns=‘C’,
values=‘E’)

Thanks

On Fri, Mar 4, 2016 at 10:51 AM, Bryan Van de Ven
<>
wrote:
Bokeh can definitely re-create this plot.
Currently, positioning of things with “categorical
coordinates” is a little clunky, and we hope to make it
better soon, but it’s still quite possible. You can see
an example of positioning quads and test with categorial
coordinates here

There is also a Span annotation to add lines like
the vertical dotted one in your plot:

Thanks,

Bryan

On Mar 4, 2016, at 9:39 AM, Tong Sun <>
wrote:

Hi,

I’m new to Bokeh from matplotlib (actually I’m
totally new to matplotlib and Python as well), so I
understand that I need to do a lot of reading before I
can pick up the speed.

Meanwhile, I’m wondering if it is possible to
do this at all with Bokeh?

Full code at ,
re-posted below:

import numpy as
np

import matplotlib.pyplot as
plt

import pandas as
pd

import seaborn as
sns
sns
.set_style(“white”) #for aesthetic purpose
only

fake data

df
= pd.DataFrame({‘A’: np.random.choice([‘foo’,
‘bar’], 100),

‘B’: np.random.choice([‘one’, ‘two’, ‘three’],
100),

‘C’: np.random.choice([‘I1’, ‘I2’, ‘I3’,
‘I4’], 100),

‘D’: np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

p
= pd.pivot_table(df, index=[‘A’,‘B’],
columns=‘C’, values=‘D’)

e
= pd.pivot_table(df, index=[‘A’,‘B’],
columns=‘C’, values=‘E’)

ax
= p.plot(kind=‘barh’, xerr=e, width=0.85)

for r in ax.patches:

if r.get_x() < 0: # it it’s a negative bar

    ax

.text(0.25, # set label on the opposite side

            r

.get_y() + r.get_height()/5., # y

“{:” “>7.1f}%”.format(r.get_x()*100), #
text

            bbox

={“facecolor”:“red”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”, zorder=10)

else:

    ax

.text(-1.5, # set label on the opposite side

            r

.get_y() + r.get_height()/5., # y

“{:” “>6.1f}%”.format(r.get_width()*100),

            bbox

={“facecolor”:“green”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”, zorder=10)

plt
.tight_layout()

Thanks


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 .
To post to this group, send email to .
To view this discussion on the web visit .
For more options, visit .


You received this message because you are
subscribed to a topic in the Google Groups “Bokeh
Discussion - Public” group.
To unsubscribe from this topic, visit .
To unsubscribe from this group and all its topics,
send an email to .
To post to this group, send email to .
To view this discussion on the web visit .
For more options, visit .


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 .
To post to this group, send email to .

To view this discussion on the web visit .
To view this discussion on the web visit .

  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/CAMmz1OdF0OEOR1pAvjhzaB%2BcC99AHYsbNgS4BmD8ciPAhoQmcA%40mail.gmail.com?utm_medium=email&utm_source=footer)      .

For more options, visit .


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

[email protected]

[email protected]

http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html

http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans

[email protected]

http://stackoverflow.com/a/35654997/2125837

[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io
https://groups.google.com/a/continuum.io/d/optout

https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe
[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/F4350A6E-3C4B-4800-BE41-140D0D6EBA56%40continuum.io
https://groups.google.com/a/continuum.io/d/optout

[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAMmz1OdiaV4f5dcOYCZQK7z5q0jjHUBGXNC0EX1d18Ch0TZDSg%40mail.gmail.com

For more options, visit
.

You received this message because you are subscribed to a
topic in the Google Groups “Bokeh Discussion - Public”
group.
To unsubscribe from this topic, visit .
To unsubscribe from this group and all its topics, send an
email to .
To post to this group, send email to .
https://groups.google.com/a/continuum.io/d/optout

https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe
[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/1C593E60-2BD3-4A08-AEE8-52ED6B857FC6%40continuum.io
For more options, visit .

https://groups.google.com/a/continuum.io/d/optout
https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAMmz1OdF0OEOR1pAvjhzaB%2BcC99AHYsbNgS4BmD8ciPAhoQmcA%40mail.gmail.com
https://groups.google.com/a/continuum.io/d/optout

If you don’t post the
error, we can’t help.

      Bu              t my

guess is that the pandas
pivot table has an index in
it that the chart builder doesn’t like.

···

On 3/4/16 8:48 AM, Tong Sun wrote:

        On Fri, Mar 4, 2016 at 11:33 AM, Tong

Sun [email protected]
wrote:

Sure.

Thanks for the link to the hover tooltips.

                Now, How to produce

a horizontal
(grouped) bar? I checked

http://bokeh.pydata.org/en/latest/docs/reference/charts.html#bar

but didn’t find a way to switch the bar to be horizontal.

          Moreover, I was having problem putting my data even in

a normal bar:

import numpy as np

import pandas as pd

from bokeh.charts import Bar, show, output_file

              df = pd.DataFrame({'A': np.random.choice(['foo',

‘bar’], 100),

              'B': np.random.choice(['one',

‘two’, ‘three’], 100),

              'C': np.random.choice(['I1',

‘I2’, ‘I3’, ‘I4’], 100),

              'D':

np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

              p = pd.pivot_table(df, index=['A','B'],

columns=‘C’, values=‘D’)

              e = pd.pivot_table(df, index=['A','B'],

columns=‘C’, values=‘E’)

p

TOOLS = ‘crosshair,hover’

pc = Bar(p, tools=TOOLS)

              output_file("bar.html", title="Bokeh Group

Horizontal Bar")

show(pc)

          The code error out at the step of "pc = Bar" with an

error that I don’t understand.

thanks

                  On Fri, Mar 4, 2016 at

11:17 AM, Bryan Van de Ven <>
wrote:

                    Hi

Tong,

                    It's probably best if you start with the User

Guide section on hover tooltips, and the smaller
examples there:

                            [http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool](http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#hover-tool)



                    And come back with specific questions based on

that.

                    Bryan


                        > On Mar 4, 2016, at 10:10 AM, Tong Sun

<[email protected] >
wrote:

                        >

                        > Thanks for the reply Bryan.

                        >

                        > I'll try my best to understand what

you’ve referenced, but honestly, it’d be
miles for me to reach there, as I’m totally
new to all of these.

                        >

                        > OK, the situation is that positioning

of things with “categorical coordinates” is
a little clunky currently. Now, how about
putting those values as tooltips instead? As
for the vertical dotted line, I can surely
live without it. “Getting the values out” is
most important to me.

                        >

                        > If the answer is yes, could you show me

the code to put tooltips in the horizontal
group bar charts please?

                        >

                        > Once again, the code to generate the

data is:

                        > df = pd.DataFrame({'A':

np.random.choice([‘foo’, ‘bar’], 100),

                        >

                        >

                        > 'B': np.random.choice(['one', 'two',

‘three’], 100),

                        >

                        >

                        > 'C': np.random.choice(['I1', 'I2',

‘I3’, ‘I4’], 100),

                        >

                        >

                        > 'D': np.random.randint(-10,11,100),

                        >

                        >

                        > 'E': np.random.randn(100)})

                        >

                        >

                        > p

                        > = pd.pivot_table(df, index=['A','B'],

columns=‘C’, values=‘D’)

                        >

                        > e

                        > = pd.pivot_table(df, index=['A','B'],

columns=‘C’, values=‘E’)

                        >

                        > Thanks

                        >

                        > On Fri, Mar 4, 2016 at 10:51 AM, Bryan

Van de Ven <[email protected] >
wrote:

                        > Bokeh can definitely re-create this

plot. Currently, positioning of things with
“categorical coordinates” is a little
clunky, and we hope to make it better soon,
but it’s still quite possible. You can see
an example of positioning quads and test
with categorial coordinates here

                        >

                        >         [http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html](http://bokeh.pydata.org/en/latest/docs/gallery/periodic.html)

                        >

                        >

                        > There is also a Span annotation to add

lines like the vertical dotted one in your
plot:

                        >

                        >         [http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans](http://bokeh.pydata.org/en/latest/docs/user_guide/plotting.html#spans)

                        >

                        > Thanks,

                        >

                        > Bryan

                        >

                        > > On Mar 4, 2016, at 9:39 AM, Tong

Sun <[email protected] >
wrote:

                        > >

                        > > Hi,

                        > >

                        > > I'm new to Bokeh from matplotlib

(actually I’m totally new to matplotlib and
Python as well), so I understand that I need
to do a lot of reading before I can pick up
the speed.

                        > >

                        > > Meanwhile, I'm wondering if it is

possible to do this at all with Bokeh?

                        > >

                        > >

                        > >

                        > >

                        > > Full code at [](http://stackoverflow.com/a/35654997/2125837)                            ,

re-posted below:

import numpy as
np

import matplotlib.pyplot as
plt

import pandas as
pd

import seaborn as
sns
sns
.set_style(“white”) #for aesthetic
purpose only

fake data

df
= pd.DataFrame({‘A’:
np.random.choice([‘foo’, ‘bar’], 100),

‘B’: np.random.choice([‘one’,
‘two’, ‘three’], 100),

‘C’: np.random.choice([‘I1’, ‘I2’,
‘I3’, ‘I4’], 100),

‘D’:
np.random.randint(-10,11,100),

‘E’: np.random.randn(100)})

p
= pd.pivot_table(df,
index=[‘A’,‘B’], columns=‘C’, values=‘D’)

e
= pd.pivot_table(df,
index=[‘A’,‘B’], columns=‘C’, values=‘E’)

ax
= p.plot(kind=‘barh’, xerr=e,
width=0.85)

for r in ax.patches:

if r.get_x() < 0: # it it’s a
negative bar

    ax

.text(0.25, # set label on the
opposite side

            r

.get_y() + r.get_height()/5., # y

“{:”
“>7.1f}%”.format(r.get_x()*100), # text

            bbox

={“facecolor”:“red”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”,
zorder=10)

else:

    ax

.text(-1.5, # set label on the
opposite side

            r

.get_y() + r.get_height()/5., # y

“{:”
“>6.1f}%”.format(r.get_width()*100),

            bbox

={“facecolor”:“green”,

“alpha”:0.5,

“pad”:1},

            fontsize

=10, family=“monospace”,
zorder=10)

plt
.tight_layout()

Thanks


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 .
To post to this group, send email
to .
To view this discussion on the web
visit .
For more options, visit .


You received this message because you
are subscribed to a topic in the Google
Groups “Bokeh Discussion - Public” group.
To unsubscribe from this topic, visit .
To unsubscribe from this group and all
its topics, send an email to .
To post to this group, send email to .
To view this discussion on the web
visit .
For more options, visit .


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 .
To post to this group, send email to .

To view this discussion on the web visit .
To view this discussion on the web visit
.

  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/CAMmz1OcAaiozY9T74sfTzz4GxF41%3DvL889ii99rCfpfoEb0O5g%40mail.gmail.com?utm_medium=email&utm_source=footer)      .

For more options, visit .


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

[email protected]http://stackoverflow.com/a/35654997/2125837

[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/62a44d53-740e-4936-8c41-ed6897792090%40continuum.io
https://groups.google.com/a/continuum.io/d/optout

https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe
[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/F4350A6E-3C4B-4800-BE41-140D0D6EBA56%40continuum.io
https://groups.google.com/a/continuum.io/d/optout

[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAMmz1OdiaV4f5dcOYCZQK7z5q0jjHUBGXNC0EX1d18Ch0TZDSg%40mail.gmail.com

For more options, visit
.

You received this message because you are
subscribed to a topic in the Google Groups
“Bokeh Discussion - Public” group.
To unsubscribe from this topic, visit .
To unsubscribe from this group and all its
topics, send an email to .
To post to this group, send email to .
https://groups.google.com/a/continuum.io/d/optout

https://groups.google.com/a/continuum.io/d/topic/bokeh/5MYqL6gDljk/unsubscribe
[email protected]
[email protected]
https://groups.google.com/a/continuum.io/d/msgid/bokeh/1C593E60-2BD3-4A08-AEE8-52ED6B857FC6%40continuum.io
For more options, visit .

https://groups.google.com/a/continuum.io/d/optout
https://groups.google.com/a/continuum.io/d/msgid/bokeh/CAMmz1OcAaiozY9T74sfTzz4GxF41%3DvL889ii99rCfpfoEb0O5g%40mail.gmail.com
https://groups.google.com/a/continuum.io/d/optout