from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib2tikz import save as tikz_save
import numpy
def meta_gaisser_hillas_generator(N_max, X_max, X_0, l):
def gaisser_hillas(X):
tmp1 = numpy.divide(numpy.subtract(X, X_0), (X_max - X_0))
tmp2 = (X_max - X_0) / l
tmp3 = numpy.subtract(X_max, X) / l
return N_max * numpy.power(tmp1, tmp2) * numpy.exp(tmp3)
return gaisser_hillas
fig = Figure()
ax = fig.add_subplot(111)
def_dict = {"N_max": 6E9, "X_max": 700, "X_0": 0, "l": 70}
dict_1 = def_dict.copy()
dict_2 = def_dict.copy()
dict_3 = def_dict.copy()
dict_4 = def_dict.copy()
dict_5 = def_dict.copy()
dict_1["X_0"] = dict_1["X_0"] - 200
dict_2["l"] = dict_2["l"] + 60
dict_3["l"] = dict_3["l"] - 60
dict_4["X_0"] = dict_4["X_0"] + 200
dict_5["N_max"] = 3E9
def_haisser = meta_gaisser_hillas_generator(**def_dict)
def_haisser_1 = meta_gaisser_hillas_generator(**dict_1)
def_haisser_2 = meta_gaisser_hillas_generator(**dict_2)
def_haisser_3 = meta_gaisser_hillas_generator(**dict_3)
def_haisser_4 = meta_gaisser_hillas_generator(**dict_4)
def_haisser_5 = meta_gaisser_hillas_generator(**dict_5)
func_dict = {}
func_dict[r"default"] = def_haisser
func_dict[r"$N_\\textrm{max}=3 \\cdot 10^9$"] = def_haisser_5
func_dict[r"$X_0+200$"] = def_haisser_4
func_dict[r"$X_0-200$"] = def_haisser_1
func_dict[r"$\\lambda+60$"] = def_haisser_2
func_dict[r"$\\lambda-60$"] = def_haisser_3
x = numpy.arange(0, 2000, 1)
for label, func in func_dict.items():
ax.plot(x, func(x), label=label)
#ax.legend(bbox_to_anchor=(1.05, 1), loc=3, borderaxespad=0.)
#ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=3, mode="expand", borderaxespad=0.)
ax.legend(bbox_to_anchor=(0., 1.05, 1., .102), loc=3, ncol=3, mode="expand", borderaxespad=0.)
cav = FigureCanvas(fig)
fig.tight_layout()
fig.savefig("gaisser_hillas.png", bbox_inches='tight', dpi=1200)
tikz_save("gaisser_hillastex", fig)
Result: