diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index c96026736074bc29497073e5669d557fdc6d647d..52b1121e7b8f165476d3c27d9e24b077a731f8e5 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -701,12 +701,23 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): self._model_setup = model_setup self._labels = None self._data = self._prepare_data(data) + default_plot_name = self.plot_name + # draw full detail plot + self.plot_name = default_plot_name + "_full_detail" self._plot() self._save() - # draw also a vertical version - self.plot_name += "_vertical" + # draw also a vertical full detail version + self.plot_name = default_plot_name + "_full_detail_vertical" self._plot_vertical() self._save() + # draw default plot with only model comparison + self.plot_name = default_plot_name + self._plot(single_model_comparison=True) + self._save() + # draw also a vertical full detail version + self.plot_name = default_plot_name + "_vertical" + self._plot_vertical(single_model_comparison=True) + self._save() def _prepare_data(self, data: pd.DataFrame) -> pd.DataFrame: """ @@ -724,12 +735,13 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): self._labels = [str(i) + "d" for i in data.index.levels[1].values] return data.stack(level=0).reset_index(level=2, drop=True).reset_index(name="data") - def _plot(self): + 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)) - order = self._create_pseudo_order() - sns.boxplot(x="comparison", y="data", hue="ahead", data=self._data, whis=1., ax=ax, palette="Blues_d", + data = self._filter_comparisons(self._data) if single_model_comparison is True else self._data + order = self._create_pseudo_order(data) + sns.boxplot(x="comparison", y="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(y=0, color="grey", linewidth=.5) @@ -740,11 +752,12 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): ax.legend(handles, self._labels) plt.tight_layout() - def _plot_vertical(self): + def _plot_vertical(self, single_model_comparison=False): """Plot skill scores of the comparisons, but vertically aligned.""" fig, ax = plt.subplots() - order = self._create_pseudo_order() - sns.boxplot(y="comparison", x="data", hue="ahead", data=self._data, whis=1., ax=ax, palette="Blues_d", + data = self._filter_comparisons(self._data) if single_model_comparison is True else self._data + order = self._create_pseudo_order(data) + 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) @@ -754,12 +767,17 @@ class PlotCompetitiveSkillScore(AbstractPlotClass): ax.legend(handles, self._labels) plt.tight_layout() - def _create_pseudo_order(self): + def _create_pseudo_order(self, data): """Provide first predefined elements and append all remaining.""" first_elements = [f"{self._model_setup}-persi", "ols-persi", f"{self._model_setup}-ols"] - uniq, index = np.unique(first_elements + self._data.comparison.unique().tolist(), return_index=True) + first_elements = list(filter(lambda x: x in data.comparison.tolist(), first_elements)) + uniq, index = np.unique(first_elements + data.comparison.unique().tolist(), return_index=True) return uniq[index.argsort()] + def _filter_comparisons(self, data): + 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]: """ Calculate axis limits from data (Can be used to set axis extend).