pyplot改变馅饼切片字体

时间:2015-11-30 12:24:08

标签: python matplotlib

我试图创建一个类似于此的基本饼图:

http://matplotlib.org/1.2.1/examples/pylab_examples/pie_demo.html

from pylab import *

# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])

# The slices will be ordered and plotted counter-clockwise.
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
colors = 'black', 'blue', 'green', 'red'
fracs = [15, 30, 45, 10]
explode=(0, 0.05, 0, 0)

pie(fracs, explode=explode, labels=labels, colors=colors
                autopct='%1.1f%%', shadow=True, startangle=90)

title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5})

show()

然而,我的一个切片将是黑色,我想改变该切片的字体。我环顾四周但却无法找到任何改变一个切片的指令。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

你能做的是:

import matplotlib.pyplot as plt
from matplotlib.gridspec import GridSpec

# Some data

labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fracs = [15, 30, 45, 10]
colors = 'black', 'blue', 'green', 'red'
explode = (0, 0.05, 0, 0)

pie_colours = plt.pie(fracs, labels=labels, colors=colors,
                                autopct='%.0f%%',
                                shadow=True,)# radius=0.5)

pie_colours[2][0].set_color('y')
# Make the labels on the small plot easier to read.
for texts in pie_colours[1]:
    texts.set_size('smaller')
for autotexts in pie_colours[2]:
    autotexts.set_size('x-small')

plt.show()

我编辑了this example来获得它。