Mercurial > repos > muon-spectroscopy-computational-project > larch_plot
diff larch_plot.py @ 1:002c18a3e642 draft
planemo upload for repository https://github.com/MaterialsGalaxy/larch-tools/tree/main/larch_plot commit 1cf6d7160497ba58fe16a51f00d088a20934eba6
author | muon-spectroscopy-computational-project |
---|---|
date | Wed, 06 Dec 2023 13:04:06 +0000 |
parents | 886949a03377 |
children | 59d0d15a40ef |
line wrap: on
line diff
--- a/larch_plot.py Tue Nov 14 15:35:36 2023 +0000 +++ b/larch_plot.py Wed Dec 06 13:04:06 2023 +0000 @@ -9,10 +9,12 @@ import numpy as np -Y_LABELS = { +AXIS_LABELS = { "norm": r"x$\mu$(E), normalised", "dmude": r"d(x$\mu$(E))/dE, normalised", "chir_mag": r"|$\chi$(r)|", + "energy": "Energy (eV)", + "distance": "r (ang)", } @@ -21,39 +23,30 @@ for i, settings in enumerate(plot_settings): data_list = [] - e0_min = None - e0_max = None - variable = settings["variable"]["variable"] - x_min = settings["variable"]["energy_min"] - x_max = settings["variable"]["energy_max"] - plot_path = f"plots/{i}_{variable}.png" + x_variable = "energy" + y_variable = settings["variable"]["variable"] + x_min = settings["variable"]["x_limit_min"] + x_max = settings["variable"]["x_limit_max"] + y_min = settings["variable"]["y_limit_min"] + y_max = settings["variable"]["y_limit_max"] + plot_path = f"plots/{i}_{y_variable}.png" plt.figure() for group in groups: - label = group.athena_params.annotation or group.athena_params.id - if variable == "chir_mag": + params = group.athena_params + label = params.annotation or params.file or params.id + if y_variable == "chir_mag": + x_variable = "distance" x = group.r - energy_format = None else: x = group.energy - energy_format = settings["variable"]["energy_format"] - if energy_format == "relative": - e0 = group.athena_params.bkg.e0 - e0_min = find_relative_limit(e0_min, e0, min) - e0_max = find_relative_limit(e0_max, e0, max) - y = getattr(group, variable) + y = getattr(group, y_variable) if x_min is None and x_max is None: plt.plot(x, y, label=label) else: data_list.append({"x": x, "y": y, "label": label}) - if variable != "chir_mag" and energy_format == "relative": - if x_min is not None: - x_min += e0_min - if x_max is not None: - x_max += e0_max - if x_min is not None or x_max is not None: for data in data_list: index_min = None @@ -70,22 +63,15 @@ ) plt.xlim(x_min, x_max) + plt.ylim(y_min, y_max) - save_plot(variable, plot_path) + save_plot(x_variable, y_variable, plot_path) -def find_relative_limit(e0_min: "float|None", e0: float, function: callable): - if e0_min is None: - e0_min = e0 - else: - e0_min = function(e0_min, e0) - return e0_min - - -def save_plot(y_type: str, plot_path: str): +def save_plot(x_type: str, y_type: str, plot_path: str): plt.grid(color="r", linestyle=":", linewidth=1) - plt.xlabel("Energy (eV)") - plt.ylabel(Y_LABELS[y_type]) + plt.xlabel(AXIS_LABELS[x_type]) + plt.ylabel(AXIS_LABELS[y_type]) plt.legend() plt.savefig(plot_path, format="png") plt.close("all")