Menu

[r4812]: / trunk / htdocs / examples / pie_demo.py  Maximize  Restore  History

Download this file

36 lines (27 with data), 1.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
"""
Make a pie chart - see
http://matplotlib.sf.net/matplotlib.pylab.html#-pie for the docstring.
This example shows a basic pie chart with labels in figure 1, and
figure 2 uses a couple of optional features, like autolabeling the
area percentage, offsetting a slice using "explode" and addind a shadow
for a 3D effect
"""
from pylab import *
# make a square figure and axes
figure(1, figsize=(8,8))
ax = axes([0.1, 0.1, 0.8, 0.8])
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
figure(1)
pie(fracs, labels=labels)
# figure(2) showa some optional features. autopct is used to label
# the percentage of the pie, and can be a format string or a function
# which takes a percentage and returns a string. explode is a
# len(fracs) sequuence which gives the fraction of the radius to
# offset that slice.
figure(2, figsize=(8,8))
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True)
savefig('pie_demo')
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.