5

I have a pie chart that looks like:

enter image description here

I tried increasing the font size using textprops={'fontsize': 18}). However, it only changes the font-size of the percentage labels inside pie, and the labels outside remain un-affected.

I want to increase fontsize of labels A, B,C etc in above pie chart.

My code:

fig1, ax1 = plt.subplots(figsize=(24,12))
flavor_pie = ax1.pie(data2.Count_Of_labels,labels=['A','B','C','D','E','F'], autopct='%.0f%%', shadow=True, colors=colors, 
                     explode= explode1, startangle= -90, textprops={'fontsize': 18})

centre_circle = plt.Circle((0,0),0.20,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)

ax1.axis('equal')  
plt.tight_layout()
plt.show()
0

2 Answers 2

8

Try:

import matplotlib as mpl
mpl.rcParams['font.size'] = 18.0

or,

mpl.rcParams.update({'font.size': 18})

or,

import matplotlib.pyplot as plt
plt.rcParams['font.size'] = 18
Sign up to request clarification or add additional context in comments.

Comments

2

You might be using an older version of matplotlib; in any newer version both, the labels and autopercentages have the same size.

The question would hence boil down to how to set different font sizes for labels and autopercentages.

Having a pie chart like this

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
wedges, labels, autopct = ax.pie([1,2,3,4,3,2],labels=['A','B','C','D','E','F'], 
                                  autopct='%.0f%%', wedgeprops=dict(width=.7))

you can loop over the labels or autopercentages and set the fontsize like

for lab in labels:
    lab.set_fontsize(15)

or set them all at once, like

plt.setp(labels, fontsize=15)

And similar for autopct.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.