Mercurial > hg > cc > cirrus_work
view lib/python/cc/lmh/plots.py @ 202:10ff891fd656
get single graph working, tweak params various
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 05 Dec 2023 19:49:11 +0000 |
parents | 4870e14ec237 |
children | 7179c83f32ea |
line wrap: on
line source
#!/usr/bin/python3 ''' Plots using LM data''' import pylab, sys import matplotlib.pyplot as plt import matplotlib import numpy as np from numpy import loadtxt def counts(yy_file,title1,title2,**kargs): '''Plot number of responses with LM against year''' yy = loadtxt(yy_file,delimiter='\t') plt.title("%s based on LastModified data from %s"%(title1,title2)) plt.plot(yy[0:,0],yy[0:,1],color='red') plt.show() def mcounts(files,titles,units='year',block=True,percent=False,delimiter='\t'): '''Comparison plot of number of responses with LM against years in multiple crawls''' byYears = [loadtxt(f,delimiter=delimiter) for f in files] yys = [yp[:,0] for yp in byYears] yvs = [yp[:,1] for yp in byYears] if percent: for yv in yvs: yt = sum(yv) yv *= 100 yv /= yt plt.semilogy() plt.title("%s of responses with LastModified header by %s"%( "Percentage" if percent else "Number",units)) for yy, yv, title in zip(yys, yvs, titles): plt.plot(yy, yv, label=title) plt.legend(loc='best',fontsize='small') plt.grid(True) plt.show(block=block) def main(tool,args): if tool == "mcounts": if args[0] == '-p': # Don't block args.pop(0) percent = True else: percent = False if args[0] == '-n': # Don't block args.pop(0) block = False else: block = True if len(args)>2: units=args[2] else: units='month' mcounts(args[0].split(','),args[1].split(','), units=units,percent=percent,block=block) elif tool == "counts": counts(*args) else: print("Not a known function: %s"%tool) exit(1) if __name__ == '__main__': main(sys.argv[1],sys.argv[2:])