Home > Software engineering >  How can I add labels with percentage to a pie chart in Python?
How can I add labels with percentage to a pie chart in Python?

Time:06-21

I have a pie chart in this code:

import matplotlib.pyplot as plt
import pandas as pd

excel_file_path = "Chartdata.xlsx"
df = pd.read_excel(excel_file_path)

df_country = df.groupby(['Country']).sum()
df_country ['Revenue'].plot.pie()


plt.show()

It reads an Excel file, checks if there are more locations for one country and if yes, sums the revenues for the locations in the same country and then displays the data as a pie chart using matplotlib.

This is what I get:

enter image description here

  • Related