Created
July 7, 2019 13:23
-
-
Save jitsejan/0a68214baf184fbe595bbae525be8e7c to your computer and use it in GitHub Desktop.
Create a dougnut plot with Matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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