From 70f7963948547c4908bf313e5dac090a616f25b1 Mon Sep 17 00:00:00 2001 From: leufen1 <l.leufen@fz-juelich.de> Date: Fri, 9 Apr 2021 14:31:45 +0200 Subject: [PATCH] error is fixed, another try on HPC, on success /close #301 --- mlair/plotting/postprocessing_plotting.py | 36 +++++++++++++---------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index 68cab25b..4855f16c 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -671,13 +671,26 @@ class PlotClimatologicalSkillScore(AbstractPlotClass): sns.boxplot(x="terms", y="data", hue="ahead", data=self._data, ax=ax, whis=1., palette="Blues_d", showmeans=True, meanprops={"markersize": 1, "markeredgecolor": "k"}, flierprops={"marker": "."}) ax.axhline(y=0, color="grey", linewidth=.5) - ax.set(ylabel=f"{self._label_add(score_only)}skill score", xlabel="", title="summary of all stations") - x_min, x_max = ax.get_xlim() - ax.set_xlim([max(x_min, -xlim), min(x_max, xlim)]) + ax.set(ylabel=f"{self._label_add(score_only)}skill score", xlabel="", title="summary of all stations", + ylim=self._lim()) handles, _ = ax.get_legend_handles_labels() ax.legend(handles, self._labels) plt.tight_layout() + def _lim(self) -> Tuple[float, float]: + """ + Calculate axis limits from data (Can be used to set axis extend). + + Lower limit is the minimum of 0 and data's minimum (reduced by small subtrahend) and upper limit is data's + maximum (increased by a small addend). + + :return: + """ + limit = 5 + lower = np.max([-limit, np.min([0, helpers.float_round(self._data["data"].min() - 0.1, 2)])]) + upper = np.min([limit, helpers.float_round(self._data["data"].max() + 0.1, 2)]) + return lower, upper + @TimeTrackingWrapper class PlotCompetitiveSkillScore(AbstractPlotClass): @@ -739,7 +752,7 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): data = data.stack(level=0).reset_index(level=2, drop=True).reset_index(name="data") return data.astype({"comparison": str, "ahead": int, "data": float}) - def _plot(self, single_model_comparison=False, xlim=5): + def _plot(self, single_model_comparison=False): """Plot skill scores of the comparisons.""" size = max([len(np.unique(self._data.comparison)), 6]) fig, ax = plt.subplots(figsize=(size, size * 0.8)) @@ -751,18 +764,12 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): ax.axhline(y=0, color="grey", linewidth=.5) ax.set(ylabel="skill score", xlabel="competing models", title="summary of all stations", ylim=self._lim()) - x_min, x_max = ax.get_xlim() - print("-----------------") - print(ax.get_xlim()) - ax.set_xlim([max(x_min, -xlim), min(x_max, xlim)]) handles, _ = ax.get_legend_handles_labels() plt.xticks(rotation=90) - print(ax.get_xlim()) ax.legend(handles, self._labels) plt.tight_layout() - print(ax.get_xlim()) - def _plot_vertical(self, single_model_comparison=False, ylim=5): + def _plot_vertical(self, single_model_comparison=False): """Plot skill scores of the comparisons, but vertically aligned.""" fig, ax = plt.subplots() data = self._filter_comparisons(self._data) if single_model_comparison is True else self._data @@ -773,8 +780,6 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): # ax.axhline(x=0, color="grey", linewidth=.5) ax.axvline(x=0, color="grey", linewidth=.5) ax.set(xlabel="skill score", ylabel="competing models", title="summary of all stations", xlim=self._lim()) - y_min, y_max = ax.get_ylim() - ax.set_ylim([max(y_min, -ylim), min(y_max, ylim)]) handles, _ = ax.get_legend_handles_labels() ax.legend(handles, self._labels) plt.tight_layout() @@ -799,8 +804,9 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): :return: """ - lower = np.min([0, helpers.float_round(self._data.min()[2], 2) - 0.1]) - upper = helpers.float_round(self._data.max()[2], 2) + 0.1 + limit = 5 + lower = np.max([-limit, np.min([0, helpers.float_round(self._data.min()[2], 2) - 0.1])]) + upper = np.min([limit, helpers.float_round(self._data.max()[2], 2) + 0.1]) return lower, upper -- GitLab