What else can we do with the matplotlib pie chart?


In the context of this exercise, what else can we do with the matplotlib pie chart?


For the matplotlib pie chart, you can set several parameters to change its appearance.

One parameter you can set is the labelDistance, which sets the radial distance that the labels are drawn from the wedges. By default this value is 1.1.

Another useful parameter is the startangle, which rotates the start of the pie chart (the top of it) by the angle degrees counterclockwise from the x-axis. For example, a value of 90 would rotate the pie chart 90 degrees counterclockwise.

In addition, you can set a colors parameter to set the color of each wedge manually. You can provide a list of colors, and if the number of colors in the list is less than the number of wedges, it will cycle through them. For example, you can set it like plt.pie(colors=["red", "blue", "green"], ...).

Another useful parameter is the explode parameter, which can be used to set the wedges to be some distance from the center of the chart, by providing one value per wedge. This essentially makes the wedges stick out of the pie chart.


Thankyou for providing such useful knowledge @jephos249.

Hi! I notice the texts on the pie chart is a bit hard to see compared to the size of the pie chart. How can we change the font size of the labels and percentage on the chart?

Thank you!

How do we use ‘explode’ in the plt.pie? I tried plt.pie(num_hardest_reported, labels = unit_topics, autopct = ‘%1d%%’,startangle = 90, explode). It didnt work.

I think you pass a lists of distances (one for each wedge) to the keyword explode.
For example plt.pie(…, explode=[0,0,0.1,0,0] will pull one wedge out for emphasis.