Skip to content

Instantly share code, notes, and snippets.

@davidbradway
Forked from brinnaebent/bf1_9.py
Created September 9, 2020 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidbradway/2732b387419f23a7d6422cd09e8b9320 to your computer and use it in GitHub Desktop.
Save davidbradway/2732b387419f23a7d6422cd09e8b9320 to your computer and use it in GitHub Desktop.
import pandas as pd
import matplotlib.pyplot as plt
# Import Data
data = pd.read_csv('scrubbed.csv')
data.head()
#Prepare "shapes" column for donut plot entry
shapes = data['shape'].value_counts(normalize=True) * 100
Keys = shapes.keys().to_list()
Percent = shapes.to_list()
fig = plt.figure(figsize=(20,20)) # Create matplotlib figure
plt.rcParams.update({'font.size': 40, 'font.family': 'monospace'})
labels = Keys
sizes = Percent
colors = ['steelblue', 'lightseagreen', 'lightslategrey', 'teal', 'lavender', 'honeydew', 'darkseagreen', 'mediumaquamarine', 'paleturquoise', 'skyblue', 'thistle', 'plum', 'orchid', 'slateblue', 'dimgray', 'lightgrey', 'mediumpurple']
# Plot Pie Chart
plt.pie(sizes,
colors=colors,
labels=labels,
autopct='%1.1f%%',
shadow=False)
# circle at the center of pie to make it look like a donut
centre_circle = plt.Circle((0,0),0.65,color='white', fc='white',linewidth=1.25)
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.show()
#Save figure
plt.savefig(('donut.png'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment