views:

477

answers:

3

I'm using some simple matplotlib functions to draw a pie chart:

f = figure(...) pie(fracs, explode=explode, ...)

However, I couldn't find out how to set a default font color, line color, font size – or pass them to pie(). How is it done?

+1  A: 

Global default colors, line widths, sizes etc, can be adjusted with the rcParams dictionary:

import matplotlib
matplotlib.rcParams['text.color'] = 'r'
matplotlib.rcParams['lines.linewidth'] = 2

A complete list of params can be found here.

You could also adjust the line width after you draw your pie chart:

from matplotlib import pyplot as plt
fig = plt.figure(figsize=(8,8))
pieWedgesCollection = plt.pie([10,20,50,20],labels=("one","two","three","four"),colors=("b","g","r","y"))[0] #returns a list of matplotlib.patches.Wedge objects
pieWedgesCollection[0].set_lw(4) #adjust the line width of the first one.

Unfortunately, I can not figure out a way to adjust the font color or size of the pie chart labels from the pie method or the Wedge object. Looking in the source of axes.py (lines 4606 on matplotlib 99.1) they are created using the Axes.text method. This method can take a color and size argument but this is not currently used. Without editing the source, your only option may be to do it globally as described above.

Mark
Thank you, that's most helpful. One addition: To set the line widht of the actual wedge, you have to use (for the first wedge):pieWedgesCollection[0][0].set_linewidth(0)
Sam
A: 
matplotlib.rcParams['font.size'] = 24

does change the pie chart labels font size

Bob