Skip to content

Instantly share code, notes, and snippets.

@chyngyz
Last active July 19, 2018 10:30
Show Gist options
  • Save chyngyz/0c2b68fb6734c4e6ce650910a694aa7e to your computer and use it in GitHub Desktop.
Save chyngyz/0c2b68fb6734c4e6ce650910a694aa7e to your computer and use it in GitHub Desktop.
Matplotlib donut chart
import matplotlib.pyplot as plt
config_colors = {
'red': '#f05e5e',
'orange': '#ffcf62',
'green': '#8fc980',
'blue': '#695ff6',
'purple': '#413aa1',
'grey': '#84839c'
}
# create data
size_of_groups=[25,25,25,25]
colors = [config_colors['red'], config_colors['orange'], config_colors['blue'], config_colors['green']]
# Figure size 1inch by 1inch (80px by 80px)
plt.figure(figsize=(3, 3))
# Create a pieplot
plt.pie(size_of_groups, colors=colors)
#plt.show()
# add a circle at the center
my_circle=plt.Circle( (0,0), 0.7, color='white')
p=plt.gcf()
p.gca().add_artist(my_circle)
plt.axis('equal')
# Uncomment to show
# plt.show()
plt.savefig('foo.png', bbox_inches='tight', transparent="True", pad_inches=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment