So this is probably a very basic question but I can't find an answer to it anywhere.
I'm trying to create some pie charts and I've managed to get them looking how I want to for the most part but when it comes to getting the percent sign to show up inside the pie slices themselves I just can't get it to work.
As I understand it, including autopct='%.1f%%'
in plt.pie()
should do exactly what I want but it just doesn't work no matter what I do. I've tried copying other people's code and seeing if it works with that but nope; all I'm getting is "30" inside the pie slices instead of "30%."
I'm hoping it's just a simple fix but nothing I've tried is working so any help would be greatly appreciated!
Edit: This is the exact code as it stands:
from matplotlib import rc
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.rcParams.update(plt.rcParamsDefault)
mpl.rcParams['text.usetex'] = True
plt.style.use('seaborn')
rc('font', **{'family': 'serif', 'serif': ['Computer Modern']})
rc('text', usetex=True)
values = [7, 3, 5, 1, 1, 1]
labels = ["18–24", "25–34", "35–44", "45–54", "55–64", "$>$65"]
fig, ax = plt.subplots(figsize=(7,7))
plt.pie(values, autopct='%.1f%%',
wedgeprops={"linewidth" : 2.0, "edgecolor": "white"},
textprops={'size': 'xx-large'})
plt.tight_layout()
plt.legend(labels=labels, loc='best')
plt.show()
CodePudding user response:
I just ran this little block:
plt.pie([30, 25], autopct='%.1f%%')
And it gave me this:
So I don't think your issue is in the plt.pie()
or autopct='%.1f%%'