Creating Pie Chart from Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thierry Lam

    #1

    Creating Pie Chart from Python

    Let's say I have the following data:

    500 objects:
    -100 are red
    -300 are blue
    -the rest are green

    Is there some python package which can represen the above information
    in a pie chart?

    Thanks
    Thierry

  • jepler@unpythonic.net

    #2
    Re: Creating Pie Chart from Python

    There are many.

    One choice would be Tkinter's Canvas.

    def frac(n): return 360. * n / 500

    import Tkinter
    c = Tkinter.Canvas( width=100, height=100); c.pack()
    c.create_arc((2 ,2,98,98), fill="red", start=frac(0), extent = frac(100))
    c.create_arc((2 ,2,98,98), fill="blue", start=frac(100) , extent = frac(400))
    c.create_arc((2 ,2,98,98), fill="green", start=frac(400) , extent = frac(100))
    c.mainloop()

    Jeff

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.6 (GNU/Linux)

    iD8DBQFDKZK8Jd0 1MZaTXX0RAuxuAJ 9F9jktcSCB3fnQM CUG/9B2Ai+gHwCfbVEx
    AACjDeSJO/6rj6BCBmirCKo=
    =QXkW
    -----END PGP SIGNATURE-----

    Comment

    • Ken Seehart

      #3
      Re: Creating Pie Chart from Python

      Thierry Lam wrote:[color=blue]
      > Let's say I have the following data:
      >
      > 500 objects:
      > -100 are red
      > -300 are blue
      > -the rest are green
      >
      > Is there some python package which can represen the above information
      > in a pie chart?
      >
      > Thanks
      > Thierry
      >[/color]

      What is the user interface context?

      Is it a web page? Do you want to create image files with pie chart? If
      yes to either of these, try gdchart.

      Download GDChart - GDChart 0.11.2, Library (C API, perl mod) for creating charts and graphs in GIF format (web/CGI use)






      Comment

      • Giovanni Dall'Olio

        #4
        Re: Creating Pie Chart from Python

        PyChart?

        Comment

        • John Hunter

          #5
          Re: Creating Pie Chart from Python

          >>>>> "Thierry" == Thierry Lam <lamthierry@gma il.com> writes:

          Thierry> Let's say I have the following data: 500 objects: -100
          Thierry> are red -300 are blue -the rest are green

          Thierry> Is there some python package which can represen the above
          Thierry> information in a pie chart?


          It looks like in python there is more than one way to make a pie
          chart. Here's another

          from pylab import figure, pie, show
          N, red, blue = 500, 100, 300
          green = N - (red + blue)
          figure(figsize= (6,6))
          pie( (red, blue, green),
          labels=('red', 'blue', 'green'),
          colors=('red', 'blue', 'green'),)
          show()

          A screenshot of a slightly more elaborate example is at



          JDH

          Comment

          • Thierry Lam

            #6
            Re: Creating Pie Chart from Python

            Those python pie chart add ons are not very useful. For my specific pie
            chart, I have some 6-8 items to show up and some of them occupy only
            2-5% of the pie. This cause the names and percentages to overlap each
            other.

            Comment

            Working...