Pie chart with Python
A pie chart shows how a total amount is divided between different categorical variables as a circle divided into proportional segments. Each categorical value corresponds with a single slice of the circle, and each arc length indicates the proportion of each category.
More about: Pie chart
Pie chart
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
'unhcrpyplotstyle','pie'])
plt.style.use([
#load and reshape the data
= pd.read_csv('https://raw.githubusercontent.com/GDS-ODSSS/unhcr-dataviz-platform/master/data/part_to_a_whole/pie.csv')
df
#compute data for plotting
= df['funding_type']
labels = df['funding_value']
values
#plot the chart
= plt.subplots()
fig, ax =ax.pie(values, labels=labels, autopct='%1.1f%%', pctdistance = 0.75, counterclock=False, startangle=-270)
pie
#set chart title
'UNHCR Funding (as of February 2022)')
ax.set_title(
#set chart source and copyright
'Source: UNHCR', (0,0), (0, -25), xycoords='axes fraction', textcoords='offset points', va='top', color = '#666666', fontsize=9)
plt.annotate('©UNHCR, The UN Refugee Agency', (0,0), (0, -35), xycoords='axes fraction', textcoords='offset points', va='top', color = '#666666', fontsize=9)
plt.annotate(
#adjust chart margin and layout
fig.tight_layout()
#show chart
plt.show()