Module plotting
[hide private]
[frames] | no frames]

Source Code for Module plotting

 1  """This module has wrapper functions to quickly create charts 
 2  """ 
 3   
 4  import pylab as pl 
 5  import matplotlib.pyplot as plt 
 6  import tempfile 
 7   
8 -def getbar(pos,val,xticks=None,xlabel='',ylabel='',title='Barchart',):
9 """Creates horizontal bar graph and save in to temporary file having .png extension. 10 This functions returns the path of the generated file 11 12 @param pos:list of positions of data on x-axis 13 @param val:list of heights 14 @param xticks:list of markers to rename x-axix values 15 @param xlabel: label for x-axis 16 @param ylabel: label for y-axix 17 @param title: title of the plot 18 @return : path of the generated graph 19 """ 20 pl.clf() 21 pl.bar(pos,val, align='center') 22 if xticks!=None: 23 pl.xticks(pos, xticks) 24 pl.xlabel(xlabel) 25 pl.ylabel(ylabel) 26 pl.title(title) 27 pl.grid(True) 28 tmpfile= tempfile.mktemp()+'.png' 29 plt.savefig(tmpfile) 30 pl.clf() 31 return tmpfile
32 33 34
35 -def getpie(values,lbls):
36 """Creates a simple pie chart and save in to temporary file having .png extension. 37 This functions returns the path of the generated file 38 39 @param values: values to be plot 40 @param lbls: labels in requence 41 @return: path of the generated graph 42 """ 43 from pylab import figure, pie, show, clf 44 clf() 45 figure(figsize=(6,6)) 46 colors=('red', 'blue', 'green') 47 pie(values,labels=lbls) 48 tmpfile= tempfile.mktemp()+'.png' 49 plt.savefig(tmpfile) 50 clf() 51 return tmpfile
52