model-vs-model.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env python3
  2. import sys
  3. from decimal import Decimal
  4. import numpy as np
  5. import matplotlib.pyplot as plt
  6. import matplotlib as mpl
  7. import vcclib
  8. # n.b.: ell is l spelled out to prevent confusion with the 1 character
  9. def main(argv):
  10. argv2 = argv[1:]
  11. plot_path = argv2.pop(0)
  12. model1_name = argv2.pop(0)
  13. model1_t1 = Decimal(argv2.pop(0))
  14. model1_ell = Decimal(argv2.pop(0))
  15. model1_t1_err_low = Decimal(argv2.pop(0))
  16. model1_ell_err_low = Decimal(argv2.pop(0))
  17. model1_t1_err_up = Decimal(argv2.pop(0))
  18. model1_ell_err_up = Decimal(argv2.pop(0))
  19. model2_name = argv2.pop(0)
  20. model2_t1 = Decimal(argv2.pop(0))
  21. model2_ell = Decimal(argv2.pop(0))
  22. model2_t1_err_low = Decimal(argv2.pop(0))
  23. model2_ell_err_low = Decimal(argv2.pop(0))
  24. model2_t1_err_up = Decimal(argv2.pop(0))
  25. model2_ell_err_up = Decimal(argv2.pop(0))
  26. max_j = int(argv2.pop(0))
  27. model1_t1_sig = vcclib.sigfigs([model1_t1,
  28. model1_t1_err_low,
  29. model1_t1_err_up])[0]
  30. model1_ell_sig = vcclib.sigfigs([model1_ell,
  31. model1_ell_err_low,
  32. model1_ell_err_up])[0]
  33. model2_t1_sig = vcclib.sigfigs([model2_t1,
  34. model2_t1_err_low,
  35. model2_t1_err_up])[0]
  36. model2_ell_sig = vcclib.sigfigs([model2_ell,
  37. model2_ell_err_low,
  38. model2_ell_err_up])[0]
  39. model1_t1_str = np.format_float_positional(model1_t1_sig, 3,
  40. fractional=False)
  41. model1_ell_str = np.format_float_positional(-model1_ell_sig, 3,
  42. fractional=False)
  43. model2_t1_str = np.format_float_positional(model2_t1_sig, 3,
  44. fractional=False)
  45. model2_ell_str = np.format_float_positional(-model2_ell_sig, 3,
  46. fractional=False)
  47. xs = [x+1 for x in range(max_j)]
  48. ys_model1 = [model1_t1 * (x)**-model1_ell for x in xs]
  49. ys_model1_low = [model1_t1_err_low * (x)**-model1_ell_err_low for x in xs]
  50. ys_model1_up = [model1_t1_err_up * (x)**-model1_ell_err_up for x in xs]
  51. ys_model2 = [model2_t1 * (x)**-model2_ell for x in xs]
  52. ys_model2_low = [model2_t1_err_low * (x)**-model2_ell_err_low for x in xs]
  53. ys_model2_up = [model2_t1_err_up * (x)**-model2_ell_err_up for x in xs]
  54. plt.rc('text', usetex=True)
  55. plt.rc('font', family='serif', size=18)
  56. mpl.rcParams["text.latex.preamble"] = \
  57. "\\usepackage{relsize}\n\\usepackage{xspace}"
  58. plt.plot(xs, ys_model1, 'b--',
  59. label=r"{}: $P_j={} j^{{{}}}$".format(
  60. model1_name, model1_t1_str, model1_ell_str))
  61. plt.fill_between(xs, ys_model1_low, ys_model1_up,
  62. color='blue', alpha=0.2)
  63. plt.plot(xs, ys_model2, 'r-',
  64. label=r"{}: $P_j={} j^{{{}}}$".format(
  65. model2_name, model2_t1_str, model2_ell_str))
  66. plt.fill_between(xs, ys_model2_low, ys_model2_up,
  67. color='red', alpha=0.2)
  68. plt.xlabel("$j=$ Experience")
  69. plt.ylabel("$P_j$")
  70. plt.xlim(left=1)
  71. plt.legend(loc="upper right")
  72. plt.tight_layout()
  73. plt.savefig(plot_path)
  74. if __name__ == '__main__':
  75. main(sys.argv)