Can't Figure Out How to Build a Pie Chart

I’d like to construct a pie chart. Currently, the documentation covers donut charts. Visually, those appear to be the closest to what I’m looking for, but I don’t know how I’d go about leveraging the Donut class to construct a pie chart. I was told by someone running the Bokeh Twitter page to check out wedges. That wasn’t very helpful.

Is there any working example of a pie chart? Ultimately, I will want to embed the chart in a webpage.

I’ve also asked on StackOverflow: http://stackoverflow.com/questions/29201177/how-do-i-create-a-pie-chart-using-bokeh

Thanks.

To be fair, Twitter is not exactly conducive to technical discussions. Here is a simple Pie chart using wedge, which takes a center point and radius as parameters, together with a list of start and end angles (currently in radians) for each wedge you want.

    from bokeh.plotting import *
    from numpy import pi

    # define starts/ends for wedges from percentages of a circle
    percents = [0, 0.3, 0.4, 0.6, 0.9, 1]
    starts = [p*2*pi for p in percents[:-1]]
    ends = [p*2*pi for p in percents[1:]]

    # a color for each pie piece
    colors = ["red", "green", "blue", "orange", "yellow"]

    # create a figure and add a wedge glyph to it
    p = figure()
    p.wedge(x=0, y=0, radius=1, start_angle=starts, end_angle=ends, color=colors)

    # display/save everythin
    output_file("pie.html")
    show(p)

If you get a chance, please update the SO question.

Thanks,

Bryan

···

On Mar 22, 2015, at 8:48 PM, Greg Thompson Jr. <[email protected]> wrote:

I'd like to construct a pie chart. Currently, the documentation covers donut charts. Visually, those appear to be the closest to what I'm looking for, but I don't know how I'd go about leveraging the `Donut` class to construct a pie chart. I was told by someone running the Bokeh Twitter page to check out wedges. That wasn't very helpful.

Is there any working example of a pie chart? Ultimately, I will want to embed the chart in a webpage.

I've also asked on StackOverflow: python - How do I create a pie chart using Bokeh? - Stack Overflow

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/f844ae2b-2b12-4d10-ae39-3aac379e7474%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

This does not work. Is your example supposed to display anything?

···

On Sunday, March 22, 2015 at 10:20:39 PM UTC-4, Bryan Van de ven wrote:

To be fair, Twitter is not exactly conducive to technical discussions. Here is a simple Pie chart using wedge, which takes a center point and radius as parameters, together with a list of start and end angles (currently in radians) for each wedge you want.

from bokeh.plotting import *

from numpy import pi



# define starts/ends for wedges from percentages of a circle

percents = [0, 0.3, 0.4, 0.6, 0.9, 1]

starts = [p*2*pi for p in percents[:-1]]

ends = [p*2*pi for p in percents[1:]]



# a color for each pie piece

colors = ["red", "green", "blue", "orange", "yellow"]



# create a figure and add a wedge glyph to it

p = figure()

p.wedge(x=0, y=0, radius=1, start_angle=starts, end_angle=ends, color=colors)



# display/save everythin  

output_file("pie.html")

show(p)

If you get a chance, please update the SO question.

Thanks,

Bryan

On Mar 22, 2015, at 8:48 PM, Greg Thompson Jr. [email protected] wrote:

I’d like to construct a pie chart. Currently, the documentation covers donut charts. Visually, those appear to be the closest to what I’m looking for, but I don’t know how I’d go about leveraging the Donut class to construct a pie chart. I was told by someone running the Bokeh Twitter page to check out wedges. That wasn’t very helpful.

Is there any working example of a pie chart? Ultimately, I will want to embed the chart in a webpage.

I’ve also asked on StackOverflow: http://stackoverflow.com/questions/29201177/how-do-i-create-a-pie-chart-using-bokeh

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/f844ae2b-2b12-4d10-ae39-3aac379e7474%40continuum.io.

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

My apologies. I ran the code from my local branch, which has a much-improved auto-ranging functionality that is yet to be merged. For Bokeh 0.8.1 and below you will need to specify a range explicitly for this particular kind of plot:

   from bokeh.plotting import *
   from numpy import pi

   # define starts/ends for wedges from percentages of a circle
   percents = [0, 0.3, 0.4, 0.6, 0.9, 1]
   starts = [p*2*pi for p in percents[:-1]]
   ends = [p*2*pi for p in percents[1:]]

   # a color for each pie piece
   colors = ["red", "green", "blue", "orange", "yellow"]

   # NOTE: this is the changed line
   p = figure(x_range=(-1,1), y_range=(-1,1))

   p.wedge(x=0, y=0, radius=1, start_angle=starts, end_angle=ends, color=colors)

   # display/save everythin
   output_file("pie.html")
   show(p)

Bokeh >0.9 will correctly compute the bounding area of all glyphs, not just "pointlike" marker glyphs, and setting the range inputs like this will not be required.

Thanks,

Bryan

···

On Mar 22, 2015, at 11:12 PM, Greg Thompson Jr. <[email protected]> wrote:

This does not work. Is your example supposed to display anything?

On Sunday, March 22, 2015 at 10:20:39 PM UTC-4, Bryan Van de ven wrote:
To be fair, Twitter is not exactly conducive to technical discussions. Here is a simple Pie chart using wedge, which takes a center point and radius as parameters, together with a list of start and end angles (currently in radians) for each wedge you want.

    from bokeh.plotting import *
    from numpy import pi

    # define starts/ends for wedges from percentages of a circle
    percents = [0, 0.3, 0.4, 0.6, 0.9, 1]
    starts = [p*2*pi for p in percents[:-1]]
    ends = [p*2*pi for p in percents[1:]]

    # a color for each pie piece
    colors = ["red", "green", "blue", "orange", "yellow"]

    # create a figure and add a wedge glyph to it
    p = figure()
    p.wedge(x=0, y=0, radius=1, start_angle=starts, end_angle=ends, color=colors)

    # display/save everythin
    output_file("pie.html")
    show(p)

If you get a chance, please update the SO question.

Thanks,

Bryan

> On Mar 22, 2015, at 8:48 PM, Greg Thompson Jr. <[email protected]> wrote:
>
> I'd like to construct a pie chart. Currently, the documentation covers donut charts. Visually, those appear to be the closest to what I'm looking for, but I don't know how I'd go about leveraging the `Donut` class to construct a pie chart. I was told by someone running the Bokeh Twitter page to check out wedges. That wasn't very helpful.
>
> Is there any working example of a pie chart? Ultimately, I will want to embed the chart in a webpage.
>
> I've also asked on StackOverflow: python - How do I create a pie chart using Bokeh? - Stack Overflow
>
> 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 bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/f844ae2b-2b12-4d10-ae39-3aac379e7474%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/e8b76a18-a658-470e-8211-8f1286d29bb8%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.