Skip to content

Instantly share code, notes, and snippets.

@Shaunakde
Created November 12, 2015 04:43
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 Shaunakde/8bc6de6d631333564da4 to your computer and use it in GitHub Desktop.
Save Shaunakde/8bc6de6d631333564da4 to your computer and use it in GitHub Desktop.
Code snippet to plot lots of pie charts in python
# -*- coding: utf-8 -*-
"""
Program to plot many pie charts
Created on Tue Nov 10 15:00:39 2015
@author: shaunak
"""
from pylab import *
#read all
f1 = open('filenames.txt','r')
f2 = open('data.txt','r')
files = f1.readlines()
data = f2.readlines()
#remove trainling returns in text files
files = [filec for filec in files if filec != '\n']
data = [datac for datac in data if datac != '\n']
f1.close()
f2.close()
#how many figures?
if len(files) < len(data):
print "There are more datapoints then filenames. Please ensure number of file names > number of datapoints."
raise ValueError('There are more datapoints then filenames.')
num = len(files)
for i in range(num):
# make a square figure and axes
figure(i, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
# The slices will be ordered and plotted counter-clockwise.
#labels = ('\\lambda_1', '\\lambda_2', '\\lambda_3')
#fracs = [i1,i2,i3]
fracs = [float(j) for j in data[i].split(',')]
_,_,autotexts = pie(fracs, explode=None, labels=None,
autopct='%1.1f%%', shadow=False, startangle=90)
for autotext in autotexts:
autotext.set_color('white')
autotext.set_fontsize('x-large')
autotext.set_fontweight('heavy')
#title('Eigen Values', bbox={'facecolor':'0.8', 'pad':5})
savefig(files[i].rstrip('\n'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment