comparison 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
comparison
equal deleted inserted replaced
201:3406742894fc 202:10ff891fd656
5 import matplotlib.pyplot as plt 5 import matplotlib.pyplot as plt
6 import matplotlib 6 import matplotlib
7 import numpy as np 7 import numpy as np
8 from numpy import loadtxt 8 from numpy import loadtxt
9 9
10 def counts(yy_file,title,delimiter='\t'): 10 def counts(yy_file,title1,title2,**kargs):
11 ''' Plot number of responses with LM against year''' 11 '''Plot number of responses with LM against year'''
12 yy = loadtxt(yy_file,delimiter=delimiter) 12 yy = loadtxt(yy_file,delimiter='\t')
13 plt.title("Number of LastModified responses in %s by year"%title) 13 plt.title("%s based on LastModified data from %s"%(title1,title2))
14 plt.semilogy()
15 plt.plot(yy[0:,0],yy[0:,1],color='red') 14 plt.plot(yy[0:,0],yy[0:,1],color='red')
15 plt.show()
16 16
17 def mcounts(files,titles,block=True,percent=False,delimiter='\t'): 17 def mcounts(files,titles,units='year',block=True,percent=False,delimiter='\t'):
18 '''Comparison plot of number of responses with LM against years 18 '''Comparison plot of number of responses with LM against years
19 in multiple crawls''' 19 in multiple crawls'''
20 byYears = [loadtxt(f,delimiter=delimiter) for f in files] 20 byYears = [loadtxt(f,delimiter=delimiter) for f in files]
21 yys = [yp[:,0] for yp in byYears] 21 yys = [yp[:,0] for yp in byYears]
22 yvs = [yp[:,1] for yp in byYears] 22 yvs = [yp[:,1] for yp in byYears]
26 yt = sum(yv) 26 yt = sum(yv)
27 yv *= 100 27 yv *= 100
28 yv /= yt 28 yv /= yt
29 29
30 plt.semilogy() 30 plt.semilogy()
31 plt.title("%s of responses with LastModified header by year"%( 31 plt.title("%s of responses with LastModified header by %s"%(
32 "Percentage" if percent else "Number")) 32 "Percentage" if percent else "Number",units))
33 for yy, yv, title in zip(yys, yvs, titles): 33 for yy, yv, title in zip(yys, yvs, titles):
34 plt.plot(yy, yv, label=title) 34 plt.plot(yy, yv, label=title)
35 plt.legend(loc='best',fontsize='small') 35 plt.legend(loc='best',fontsize='small')
36 plt.grid(True) 36 plt.grid(True)
37 plt.show(block=block) 37 plt.show(block=block)
38 38
39 def main(tool,args): 39 def main(tool,args):
40 if tool == "mcounts": 40 if tool == "mcounts":
41 if args[0] == '-p': 41 if args[0] == '-p':
42 # Don't block 42 # Don't block
43 args.pop(0) 43 args.pop(0)
44 percent = True 44 percent = True
45 else: 45 else:
46 percent = False 46 percent = False
47 if args[0] == '-n': 47 if args[0] == '-n':
48 # Don't block 48 # Don't block
49 args.pop(0) 49 args.pop(0)
50 block = False 50 block = False
51 else: 51 else:
52 block = True 52 block = True
53 mcounts(args[0].split(','),args[1].split(','),percent=percent,block=block) 53 if len(args)>2:
54 units=args[2]
55 else:
56 units='month'
57 mcounts(args[0].split(','),args[1].split(','),
58 units=units,percent=percent,block=block)
59 elif tool == "counts":
60 counts(*args)
54 else: 61 else:
55 print("Not a known function: %s"%tool) 62 print("Not a known function: %s"%tool)
56 exit(1) 63 exit(1)
57 64
58 if __name__ == '__main__': 65 if __name__ == '__main__':