Skip to content

Instantly share code, notes, and snippets.

@jjsantanna
Last active December 20, 2021 17:11
Show Gist options
  • Save jjsantanna/f5f72720aa11a0d660f38530c5a79107 to your computer and use it in GitHub Desktop.
Save jjsantanna/f5f72720aa11a0d660f38530c5a79107 to your computer and use it in GitHub Desktop.
pie chart matplotlib
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