changeset 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 3406742894fc
children 3e5afe881908
files lib/python/cc/lmh/plots.py
diffstat 1 files changed, 28 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/lib/python/cc/lmh/plots.py	Tue Dec 05 10:35:15 2023 +0000
+++ b/lib/python/cc/lmh/plots.py	Tue Dec 05 19:49:11 2023 +0000
@@ -7,14 +7,14 @@
 import numpy as np
 from numpy import loadtxt
 
-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 LastModified responses in %s by year"%title)
-  plt.semilogy()
+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,block=True,percent=False,delimiter='\t'):
+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]
@@ -28,8 +28,8 @@
       yv /= yt
 
   plt.semilogy()
-  plt.title("%s of responses with LastModified header by year"%(
-    "Percentage" if percent else "Number"))
+  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')
@@ -38,19 +38,26 @@
 
 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)
+    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)