ternary_plot.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import matplotlib.tri as tri
  2. import matplotlib as mpl
  3. from matplotlib import cm
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. import pandas as pd
  7. import ternary
  8. import argparse
  9. mpl.use("pgf")
  10. mpl.rcParams.update(
  11. {
  12. "pgf.texsystem": "xelatex",
  13. "font.family": "serif",
  14. "font.serif": "Times New Roman",
  15. "text.usetex": True,
  16. "pgf.rcfonts": False,
  17. }
  18. )
  19. parser = argparse.ArgumentParser()
  20. parser.add_argument('fit')
  21. args = parser.parse_args(["output/social_divide_samples.parquet"])
  22. df = pd.read_parquet(args.fit)
  23. data = {'n_authors': 2500, 'n_types': 3}
  24. cats = ['th','exp','ph']
  25. n_authors = data['n_authors']
  26. scale = 1
  27. # n_authors = 1547-1
  28. a = [df[f'probs.{k}.1'].mean() for k in 1+np.arange(n_authors)]
  29. b = [df[f'probs.{k}.3'].mean() for k in 1+np.arange(n_authors)]
  30. c = [df[f'probs.{k}.2'].mean() for k in 1+np.arange(n_authors)]
  31. a = np.array(a).flatten()
  32. b = np.array(b).flatten()
  33. c = np.array(c).flatten()
  34. s = (a+b+c)/scale
  35. a = a/s
  36. b = b/s
  37. c = c/s
  38. figure, tax = ternary.figure(scale=scale)
  39. tax.boundary(linewidth=1)
  40. tax.gridlines(linewidth=0.25, multiple=scale/5, linestyle="-.", color='black')
  41. tax.gridlines(linewidth=0.1, multiple=scale/10, linestyle="-.", color='black')
  42. tax.ticks(axis='lbr', linewidth=1, multiple=scale/5, tick_formats="%.1f")
  43. fontsize = 10
  44. tax.right_corner_label("Theory", fontsize=fontsize)
  45. tax.top_corner_label("Phenomenology", fontsize=fontsize)
  46. tax.left_corner_label("Experiment", fontsize=fontsize)
  47. tax.left_axis_label("$\\frac{p_{exp}}{p_{exp}+p_{ph}+p_{th}}$", fontsize=fontsize, offset=0.14)
  48. tax.right_axis_label("$\\frac{p_{ph}}{p_{exp}+p_{ph}+p_{th}}$", fontsize=fontsize, offset=0.14)
  49. tax.bottom_axis_label("$\\frac{p_{th}}{p_{exp}+p_{ph}+p_{th}}$", fontsize=fontsize)
  50. tax.scatter(np.array([a,b,c]).T, s=0.1, alpha=0.5, color='red')
  51. tax.get_axes().axis('off')
  52. tax.clear_matplotlib_ticks()
  53. tax.set_title(f"Fraction of (co-)authored publications for each category (theory, phenomenology, experiment)", y=1.1)
  54. x0 = 0.32
  55. y0 = 0.825
  56. dx = 0.1/2
  57. dy = -0.1*np.sqrt(3)/2
  58. plt.arrow(x0, y0, dx, dy, head_width=0.01, head_length=0.01, fc='k', ec='k')
  59. x0 = 1.075
  60. y0 = 0.1725
  61. dx = -0.1
  62. dy = 0
  63. plt.arrow(x0, y0, dx, dy, head_width=0.01, head_length=0.01, fc='k', ec='k')
  64. x0 = 0.2-0.16/2
  65. y0 = -0.16*np.sqrt(3)/2
  66. dx = 0.1/2
  67. dy = 0.1*np.sqrt(3)/2
  68. plt.arrow(x0, y0, dx, dy, head_width=0.01, head_length=0.01, fc='k', ec='k')
  69. plt.savefig(f"plots/social_divide_ternary.pgf", bbox_inches='tight')
  70. plt.savefig(f"plots/social_divide_ternary.pdf", bbox_inches='tight')
  71. plt.savefig(f"plots/social_divide_ternary.eps", bbox_inches='tight')