diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index 1cb6181ac5d1428012ce17a59b60da708085fe44..d769fabce5702ceb6bb29cf726b4ccf82657ebb4 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. @@ -671,11 +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") + 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): @@ -747,8 +762,7 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): showmeans=True, meanprops={"markersize": 3, "markeredgecolor": "k"}, flierprops={"marker": "."}, order=order) ax.axhline(y=0, color="grey", linewidth=.5) - - ax.set(ylabel="skill score", xlabel="competing models", title="summary of all stations", ylim=self._lim()) + ax.set(ylabel="skill score", xlabel="competing models", title="summary of all stations", ylim=self._lim(data)) handles, _ = ax.get_legend_handles_labels() plt.xticks(rotation=90) ax.legend(handles, self._labels) @@ -762,9 +776,8 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): sns.boxplot(y="comparison", x="data", hue="ahead", data=data, whis=1., ax=ax, palette="Blues_d", showmeans=True, meanprops={"markersize": 3, "markeredgecolor": "k"}, flierprops={"marker": "."}, order=order) - # 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()) + ax.set(xlabel="skill score", ylabel="competing models", title="summary of all stations", xlim=self._lim(data)) handles, _ = ax.get_legend_handles_labels() ax.legend(handles, self._labels) plt.tight_layout() @@ -780,7 +793,8 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): filtered_headers = list(filter(lambda x: "nn-" in x, data.comparison.unique())) return data[data.comparison.isin(filtered_headers)] - def _lim(self) -> Tuple[float, float]: + @staticmethod + def _lim(data) -> Tuple[float, float]: """ Calculate axis limits from data (Can be used to set axis extend). @@ -789,8 +803,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(data.min()[2], 2) - 0.1])]) + upper = np.min([limit, helpers.float_round(data.max()[2], 2) + 0.1]) return lower, upper