From d8197b1973ce079660b7032bfdcbfaf6c1b125e8 Mon Sep 17 00:00:00 2001 From: Felix Kleinert <f.kleinert@fz-juelich.de> Date: Thu, 10 Feb 2022 14:39:50 +0100 Subject: [PATCH] update sectorial skill score plots --- mlair/plotting/postprocessing_plotting.py | 46 +++++++++++++---------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index fa121fe8..6cf92c08 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -641,13 +641,12 @@ class PlotSectorialSkillScore(AbstractPlotClass): # pragma: no cover self._reference_dim = reference_dim self._labels = None self._model_name_for_plots = model_name_for_plots + self._sns_settings = {"hue": "ahead", "whis": 1., "palette": "Blues_r", + "showmeans": False, "flierprops": {"marker": "."}} self._data, self._reference_model = self._prepare_data(data) - logging.info("PlotSectorialSkillScore: finished _prepare_data(data)") self._plot() - logging.info("PlotSectorialSkillScore: finished _plot()") self.plot_name = self.plot_name + "_vertical" self._plot_vertical() - logging.info("PlotSectorialSkillScore: finished _plot_vertical()") @TimeTrackingWrapper def _prepare_data(self, data: xr.DataArray): @@ -659,6 +658,7 @@ class PlotSectorialSkillScore(AbstractPlotClass): # pragma: no cover name="data") return data, reference_model + @TimeTrackingWrapper def _plot(self): size = max([len(np.unique(self._data.sector)), 6]) data = self._data @@ -667,16 +667,17 @@ class PlotSectorialSkillScore(AbstractPlotClass): # pragma: no cover for ref in self._reference_model: ref_data = data[data[self._reference_dim]==ref] fig, ax = plt.subplots(figsize=(size, size * 0.8)) - sns.boxplot(x="sector", y="data", hue="ahead", data=ref_data, - whis=1, ax=ax, palette="Blues_r", - showmeans=False, #meanprops={"markersize": 3, "markeredgecolor": "k"}, - flierprops={"marker": "."}, - ) + # sns.boxplot(x="sector", y="data", hue="ahead", data=ref_data, + # whis=1, ax=ax, palette="Blues_r", + # showmeans=False, #meanprops={"markersize": 3, "markeredgecolor": "k"}, + # flierprops={"marker": "."}, + # ) + sns.boxplot(x="sector", y="data", data=ref_data, ax=ax, **self._sns_settings) ax.axhline(y=0, color="grey", linewidth=.5) ax.set(ylabel=f"skill score ({self._model_setup} vs. {ref})", xlabel="sector", title="summary of all stations", ylim=self._lim(ref_data)) handles, _ = ax.get_legend_handles_labels() - plt.xticks(rotation=45, horizontalalignment="right") + # plt.xticks(rotation=45, horizontalalignment="right") ax.legend(handles, self._labels) plt.tight_layout() pdf_pages.savefig() @@ -684,19 +685,26 @@ class PlotSectorialSkillScore(AbstractPlotClass): # pragma: no cover pdf_pages.close() plt.close('all') + @TimeTrackingWrapper def _plot_vertical(self): """Plot skill scores of the comparisons, but vertically aligned.""" - fig, ax = plt.subplots() data = self._data - sns.boxplot(y="sector", x="data", hue="ahead", data=data, whis=1.5, ax=ax, palette="Blues_r", - showmeans=False, meanprops={"markersize": 3, "markeredgecolor": "k"}, flierprops={"marker": "."}, - ) - ax.axvline(x=0, color="grey", linewidth=.5) - ax.set(xlabel=f"skill score ({self._model_setup} vs. {self._reference_model})", ylabel="sector", - title="summary of all stations", xlim=self._lim(data)) - handles, _ = ax.get_legend_handles_labels() - ax.legend(handles, self._labels) - plt.tight_layout() + plot_path = os.path.join(os.path.abspath(self.plot_folder), f"{self.plot_name}.pdf") + pdf_pages = matplotlib.backends.backend_pdf.PdfPages(plot_path) + for ref in self._reference_model: + ref_data = data[data[self._reference_dim] == ref] + fig, ax = plt.subplots() + sns.boxplot(y="sector", x="data", data=ref_data, ax=ax, **self._sns_settings) + ax.axvline(x=0, color="grey", linewidth=.5) + ax.set(xlabel=f"skill score ({self._model_setup} vs. {ref})", ylabel="sector", + title="summary of all stations", xlim=self._lim(ref_data)) + handles, _ = ax.get_legend_handles_labels() + ax.legend(handles, self._labels) + plt.tight_layout() + pdf_pages.savefig() + # close all open figures / plots + pdf_pages.close() + plt.close('all') @staticmethod def _lim(data) -> Tuple[float, float]: -- GitLab