|
From: John H. <jd...@gm...> - 2007-06-04 14:01:33
|
On 6/4/07, Erik Wickstrom <er...@er...> wrote:
I didn't see Eric answer your "oblong" part of the question. To make
it circular, use aspect='equal'
ax = fig.add_subplot(111, aspect='equal')
> -Can I give it more of a 3d look? Like the pie charts in MS Word?
enable shadow=True, eg
pie(...., shadow=True)
> -How can I reduce the size of the canvas behind the chart? There is a
> lot of empty whitespace and I need to tighten up the margins as the
> graph will be displayed inline on an html page...
Set your own axes dimensions, just make sure it is square
fig = figure(figsize=(6,6))
ax = fig.add_axes([0.05, 0.05, 0.9, 0.9], aspect='equal')
> -for the colors, do I use numbers to customize the colors, or do I
> have to use colors from a built in pallet?
You can do it either way, but if you want your colors to reflect the
magnitude of the percentage for a given slice, you will need to use a
colormap. See below
> -lastly - is it possible to print the labels inside each slice of the
> chart, instead of outside?
Unfortunately not, but there should be. I just added a new keyword
arg "labeldistance" which is a fraction of the radius at which to
print the label (default 1.1). Changes are in svn.
import matplotlib.cm as cm
from pylab import figure, show
# make a square figure and axes
fig = figure(figsize=(8,8))
ax = fig.add_axes([0.05, 0.05, 0.90, 0.90], aspect='equal')
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15,30,45, 10]
jet = cm.get_cmap('RdYlGn', 256)
scalarmap = cm.ScalarMappable(cmap=jet)
scalarmap.set_clim(0, 100)
colors = [scalarmap.to_rgba(frac) for frac in fracs]
ax.pie(fracs, labels=labels, colors=colors,
pctdistance=0.4, labeldistance=0.9,
autopct='%d%%', shadow=True)
show()
|