pie(fbfrac,labels = fblabel,autopct='%1.1f%%',pctdistance=0.8,startangle=90,colors=fbcolor)
I have the chart displaying just as I want it, with the exception that the text will stand out better inside the plot if it is white instead of black.
Right-click on one label to open the Annotation dialog. In this dialog, you can use the Font Color option to customize the color for current label. If the color has been set to Auto, it means the color of current label will follow the Font Color setting in the the Labels tab of Plot Details dialog.
Firstly, import matplotlib. To add labels, create a list of labels. To change the colors of slices, use the colors argument and pass a list of colors to it. To plot a pie chart, use the pie() method. To change the properties of wedges, use the wedgeprops argument.
Pie object returns patches, texts, autotexts
. You can loop through the texts
and autotext
and set_color
.
import matplotlib.pyplot as plt
fblabels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
fbfrac = [15, 30, 45, 10]
fbcolor = ["blue", "green", "red", "orange"]
fig, ax = plt.subplots()
patches, texts, autotexts = ax.pie(fbfrac, labels = fblabels, autopct='%1.1f%%',pctdistance=0.8,startangle=90,colors=fbcolor)
[text.set_color('red') for text in texts]
texts[0].set_color('blue')
[autotext.set_color('white') for autotext in autotexts]
plt.show()
Output
Moreover you can change the color for individual label, accessing the list item, e.g: texts[0].set_color('blue')
You can get more inspiration here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With