From 0d3326677ac4f0b13eef9d43d07b77e2a79927ef Mon Sep 17 00:00:00 2001 From: leufen1 <l.leufen@fz-juelich.de> Date: Fri, 9 Apr 2021 13:29:42 +0200 Subject: [PATCH] added limit for x or y axis --- mlair/plotting/postprocessing_plotting.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index 1cb6181a..c4f18bfd 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -659,7 +659,7 @@ class PlotClimatologicalSkillScore(AbstractPlotClass): """ return "" if score_only else "terms and " - def _plot(self, score_only): + def _plot(self, score_only, xlim=5): """ Plot climatological skill score. @@ -672,6 +672,8 @@ class PlotClimatologicalSkillScore(AbstractPlotClass): 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)]) handles, _ = ax.get_legend_handles_labels() ax.legend(handles, self._labels) plt.tight_layout() @@ -737,7 +739,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): + def _plot(self, single_model_comparison=False, xlim=5): """Plot skill scores of the comparisons.""" size = max([len(np.unique(self._data.comparison)), 6]) fig, ax = plt.subplots(figsize=(size, size * 0.8)) @@ -749,12 +751,14 @@ 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() + ax.set_xlim([max(x_min, -xlim), min(x_max, xlim)]) handles, _ = ax.get_legend_handles_labels() plt.xticks(rotation=90) ax.legend(handles, self._labels) plt.tight_layout() - def _plot_vertical(self, single_model_comparison=False): + def _plot_vertical(self, single_model_comparison=False, ylim=5): """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 @@ -765,6 +769,8 @@ 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() -- GitLab