LearnWave
Learn it. Master it.

Plotting Data using Matplotlib

Pie charts

Plot pie charts with labels, explode and autopct.

A pie chart divides a circle into sectors (wedges), each showing a part of the whole, in proportion to its value.

With Pandas: df.plot(kind='pie', y='column'). You must give the column y to plot (or use subplots=True to draw one pie for each column).

The wedge labels are the DataFrame's index values: so make the categories the index.

Customising a pie chart:

  • legend=False removes the legend box;
  • explode: a list of numbers that pulls wedges out from the centre, to highlight them;
  • autopct='%.1f%%': shows each wedge's percentage, to one decimal place;
  • colors: a list of colours for the wedges.

One column makes one pie.

One column, one pie.

Practise this lesson

Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.

No account, no email address. Opens the real product.