Last active
December 20, 2021 17:11
-
-
Save jjsantanna/f5f72720aa11a0d660f38530c5a79107 to your computer and use it in GitHub Desktop.
pie chart 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
import pandas as pd | |
import matplotlib.pyplot as plt # http://matplotlib.org/gallery.html | |
plt.style.use('ggplot') # https://matplotlib.org/3.1.1/gallery/style_sheets/style_sheets_reference.html | |
fig = plt.figure(figsize=(5, 5)) | |
ax = plt.subplot2grid((1,1), (0,0)) | |
# ax.set_title("Distribution of message 'level'") | |
total = data.values.sum() | |
def my_autopct(x): | |
return ('{:.1f}%\n({:.0f})'.format(x, total*x/100)) if x > 1 else '' | |
data.plot(ax=ax, | |
kind='pie', | |
autopct=my_autopct, | |
fontsize=10, | |
explode=(0, 0, 0.5, 0), | |
# shadow=True, | |
startangle=-85, | |
wedgeprops={'width':0.7}) | |
plt.text(0, 0, str(total)+"\n[total]", ha='center', va='center', fontsize=12) | |
ax.set_ylabel('') | |
plt.rcParams['font.family'] = 'sans-serif' | |
plt.rcParams['font.sans-serif'] = ['Helvetica'] | |
# fig.savefig('name.eps', bbox_inches='tight',format='eps', dpi=1200) | |
fig.savefig('name.png', bbox_inches='tight',format='png', dpi=1200, transparent=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment