Mercurial > hg > cc > cirrus_work
changeset 170:4870e14ec237
LM plot for multiple crawls, magnitude or %age
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 06 Nov 2023 15:55:57 +0000 |
parents | 28c0e0b2ac94 |
children | 143d2c6d56da |
files | lib/python/cc/lmh/plots.py |
diffstat | 1 files changed, 52 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/python/cc/lmh/plots.py Fri Nov 03 19:05:54 2023 +0000 +++ b/lib/python/cc/lmh/plots.py Mon Nov 06 15:55:57 2023 +0000 @@ -1,7 +1,7 @@ #!/usr/bin/python3 -''' Plots using LM data ''' +''' Plots using LM data''' -import pylab +import pylab, sys import matplotlib.pyplot as plt import matplotlib import numpy as np @@ -10,6 +10,55 @@ def counts(yy_file,title,delimiter='\t'): ''' Plot number of responses with LM against year''' yy = loadtxt(yy_file,delimiter=delimiter) - plt.title("Number of responses in %s by year"%title) + plt.title("Number of LastModified responses in %s by year"%title) plt.semilogy() plt.plot(yy[0:,0],yy[0:,1],color='red') + +def mcounts(files,titles,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 year"%( + "Percentage" if percent else "Number")) + 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 + mcounts(args[0].split(','),args[1].split(','),percent=percent,block=block) + else: + print("Not a known function: %s"%tool) + exit(1) + +if __name__ == '__main__': + main(sys.argv[1],sys.argv[2:]) + + + + +