annotate lib/python/cc/lmh/plots.py @ 206:7179c83f32ea

support semilogy from cmd line
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 07 Dec 2023 18:15:43 +0000
parents 10ff891fd656
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
169
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 #!/usr/bin/python3
170
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
2 ''' Plots using LM data'''
169
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3
170
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
4 import pylab, sys
169
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 import matplotlib.pyplot as plt
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 import matplotlib
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 import numpy as np
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 from numpy import loadtxt
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9
206
7179c83f32ea support semilogy from cmd line
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 202
diff changeset
10 def counts(yy_file,title1,title2,semiLog=False,**kargs):
202
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
11 '''Plot number of responses with LM against year'''
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
12 yy = loadtxt(yy_file,delimiter='\t')
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
13 plt.title("%s based on LastModified data from %s"%(title1,title2))
206
7179c83f32ea support semilogy from cmd line
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 202
diff changeset
14 if semiLog:
7179c83f32ea support semilogy from cmd line
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 202
diff changeset
15 plt.semilogy()
169
28c0e0b2ac94 can overlay the two
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 plt.plot(yy[0:,0],yy[0:,1],color='red')
202
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
17 plt.show()
170
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
18
202
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
19 def mcounts(files,titles,units='year',block=True,percent=False,delimiter='\t'):
170
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
20 '''Comparison plot of number of responses with LM against years
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
21 in multiple crawls'''
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
22 byYears = [loadtxt(f,delimiter=delimiter) for f in files]
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
23 yys = [yp[:,0] for yp in byYears]
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
24 yvs = [yp[:,1] for yp in byYears]
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
25
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
26 if percent:
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
27 for yv in yvs:
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
28 yt = sum(yv)
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
29 yv *= 100
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
30 yv /= yt
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
31
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
32 plt.semilogy()
202
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
33 plt.title("%s of responses with LastModified header by %s"%(
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
34 "Percentage" if percent else "Number",units))
170
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
35 for yy, yv, title in zip(yys, yvs, titles):
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
36 plt.plot(yy, yv, label=title)
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
37 plt.legend(loc='best',fontsize='small')
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
38 plt.grid(True)
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
39 plt.show(block=block)
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
40
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
41 def main(tool,args):
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
42 if tool == "mcounts":
202
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
43 if args[0] == '-p':
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
44 # Don't block
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
45 args.pop(0)
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
46 percent = True
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
47 else:
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
48 percent = False
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
49 if args[0] == '-n':
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
50 # Don't block
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
51 args.pop(0)
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
52 block = False
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
53 else:
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
54 block = True
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
55 if len(args)>2:
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
56 units=args[2]
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
57 else:
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
58 units='month'
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
59 mcounts(args[0].split(','),args[1].split(','),
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
60 units=units,percent=percent,block=block)
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
61 elif tool == "counts":
10ff891fd656 get single graph working, tweak params various
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 170
diff changeset
62 counts(*args)
170
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
63 else:
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
64 print("Not a known function: %s"%tool)
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
65 exit(1)
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
66
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
67 if __name__ == '__main__':
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
68 main(sys.argv[1],sys.argv[2:])
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
69
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
70
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
71
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
72
4870e14ec237 LM plot for multiple crawls, magnitude or %age
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 169
diff changeset
73