How to create a donut chart on Python in 3 screenshots

Elad Gvirtz
Jul 11, 2021

--

  • Donut charts are one of the most common types of data visualizations.
  • Each slice represents one component and all slices added together equal the whole.

Screenshot 1 — That your data:

import pandas as pd
import matplotlib.pyplot as plt
#create dataframedf = pd.DataFrame({
'Sales' : [50000, 122222, 2000]},index=['TV', 'Smartphones', 'DVD'])
print('Pie Chart Data')
df.head()

Screenshot 2 — That your actions:

plt.pie(df['Sales'], labels=df.index)
my_circle=plt.Circle( (0,0), 0.7, color='white')
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.show()

Screenshot 2 — Let’s make it look better:

fig = plt.figure(figsize=(12, 8))
plt.title("Sales", size=20, fontweight='bold')
plt.pie(df['Sales'], # x values
labels=df.index,
colors=['#AC3E31','#DBAE58','#484848'],
textprops={'fontsize': 14} #font size for labels)
circle=plt.Circle( (0,0), 0.6, color='white')
p=plt.gcf()
p.gca().add_artist(circle)
plt.show()

For more visualization and analytics
https://drivenn.io/

--

--

Elad Gvirtz
Elad Gvirtz

Written by Elad Gvirtz

Data driven is more than a quote — drivenn.io

No responses yet