I want to have labels with small size on a piechart in python to improve visibility here is the code
import matplotlib.pyplot as plt
frac=[1.40 , 10.86 , 19.31 , 4.02 , 1.43 , 2.66 , 4.70 , 0.70 , 0.13 , 1.48, 32.96 , 1.11 , 13.30 , 5.86]
labels=['HO0900344', 'HO0900331', 'HO0900332', 'HO0900354',
'HO0900358', 'HO0900374', 'HO0900372', 'HO0900373',
'HO0900371', 'HO0900370', 'HO0900369', 'HO0900356',
'HO0900353', 'HO0900343']
fig = plt.figure(1, figsize=(6,6))
ax = fig.add_subplot(111)
ax.axis('equal')
colors=('b', 'g', 'r', 'c', 'm', 'y', 'burlywood', 'w')
ax.pie(frac,colors=colors ,labels=labels, autopct='%1.1f%%')
plt.show()
Thanks and cheers
The simplest way to change the font size on a pie chart is directly via the textprops
argument in the pie()
function. Using the code above add it like so:
ax.pie(frac, colors=colors ,labels=labels,
autopct='%1.1f%%', textprops={'fontsize': 14})
That way you can just pass in a dictionary with your desired fontsize (e.g., 14). No messing around with rcParams
or return values from the function call.