Donut chart with Python
The donut chart is a variation of a pie charts, with the total amount divided into categories based on a proportional value. For the most part, there aren’t significant differences between a pie chart and a donut chart, so the choice of a donut over a standard circle is mostly aesthetic. One small advantage for the ring shape is that the central area can be used to show additional information such as the total amount figure.
More about: Donut chart
Donut chart
# import libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
'unhcrpyplotstyle', 'donut'])
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, wedgeprops={'width':0.5, 'edgecolor':'white', 'linewidth': 2})
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()