How to do a pie plot with Matplotlib

1 min

Here is the simplest method to do a pie plot.

import matplotlib.pyplot as plt
import pandas as pd

df = pd.DataFrame(data={"country" : ["Spain", "Germany", "USA", "Spain"]})

fig, axes = plt.subplots(1,1, figsize=(8,6))

# We do a pie plot on the axes

# Fixing the layout to fit the size

# Showing the plot
The method using matplotlib

Note the use of the .value_counts() method that gives the counts of unique values.

More on plots

If you want to know more about how to add labels, plot different types of plots, etc... checkout the other articles I wrote on the topic, just here :

Matplotlib - The Python You Need
We gathered the only Python essentials that you will probably ever need.