Skip to content

Instantly share code, notes, and snippets.

@jitsejan
Created July 7, 2019 13:23
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 jitsejan/0a68214baf184fbe595bbae525be8e7c to your computer and use it in GitHub Desktop.
Save jitsejan/0a68214baf184fbe595bbae525be8e7c to your computer and use it in GitHub Desktop.
Create a dougnut plot with Matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.style as style
import seaborn as sns
plt.rcParams["figure.figsize"] = (12,12)
# Improve style of the plots
style.use('seaborn-deep')
style.use('ggplot')
top_no = 10
pie_data = df
.groupby('country')['name']\
.nunique()\
.nlargest(top_no)\
.to_frame()
fig1, ax1 = plt.subplots()
ax1.pie(x=pie_data['name'],
labels=pie_data.index,
autopct='%1.1f%%',
startangle=180)
centre_circle = plt.Circle((0,0),0.70,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
fig.gca().set_title(f"Top {top_no} names")
ax1.axis('equal')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment