Newer
Older
Master_thesis / data / CLs / finished / f1d1 / -+ / D-True / 2287892 / helperfunctions.py
@saslie saslie on 8 Oct 2019 773 bytes new data
  1. # some helperfunctions
  2.  
  3. import matplotlib
  4. matplotlib.use("agg")
  5. import matplotlib.pyplot as plt
  6.  
  7. #Dislpay time (e.g. while generating points)
  8.  
  9. display_intervals = (
  10. ('w', 604800), # 60 * 60 * 24 * 7
  11. ('d', 86400), # 60 * 60 * 24
  12. ('h', 3600), # 60 * 60
  13. ('min', 60),
  14. ('s', 1),
  15. )
  16.  
  17. def display_time(seconds, granularity=2):
  18. result = []
  19.  
  20. for name, count in display_intervals:
  21. value = seconds // count
  22. if value:
  23. seconds -= value * count
  24. if value == 1:
  25. name = name.rstrip('s')
  26. result.append("{} {}".format(value, name))
  27. return ', '.join(result[:granularity])
  28.  
  29. def prepare_plot(title):
  30. plt.title(title)
  31. plt.grid()
  32. plt.legend(loc = 'best')
  33. plt.xlabel("q")