diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index c349f01309246a1affe60a20f6783b28237f636d..6d2d5ebd2871bb11bb74363dd4385f5abe687300 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -1008,27 +1008,50 @@ class PlotSampleUncertaintyFromBootstrap(AbstractPlotClass): self.error_measure = error_measure self.dim_name_boots = dim_name_boots self.error_unit = error_unit + self.prepare_data(data) + self._plot(orientation="v") - self._plot(data) + self.plot_name = self.plot_name + "_horizontal" + self._plot(orientation="h") - def _plot(self, data): - data_table = data.to_pandas() - n_boots = data_table.shape[0] + + self._data_table = None + self._n_boots = None + + def prepare_data(self, data: xr.DataArray): + self._data_table = data.to_pandas() + self._n_boots = self._data_table.shape[0] + + def _plot(self, orientation: str = "v"): + data_table = self._data_table + n_boots = self._n_boots size = max([len(np.unique(data_table.columns)), 6]) - fig, ax = plt.subplots(figsize=(size, size * 0.8)) + if orientation == "v": + figsize = (size, size * 0.8) + elif orientation == "h": + figsize = (size * 0.8, size) + else: + raise ValueError(f"orientation must be `v' or `h' but is: {orientation}") + fig, ax = plt.subplots(figsize=figsize) sns.boxplot(data=data_table, ax=ax, whis=1., color="white", showmeans=True, meanprops={"markersize": 3, "markeredgecolor": "k"}, flierprops={"marker": "o", "markerfacecolor": "black", "markeredgecolor": "none","markersize": 3}, boxprops={'facecolor': 'none', 'edgecolor': 'k'}, - width=.3) - ax.set_ylabel(f"{self.error_measure} (in {self.error_unit})") - ax.set_xticklabels(ax.get_xticklabels(), rotation=45) + width=.3, orient=orientation) + if orientation == "v": + ax.set_ylabel(f"{self.error_measure} (in {self.error_unit})") + ax.set_xticklabels(ax.get_xticklabels(), rotation=45) + elif orientation == "h": + ax.set_xlabel(f"{self.error_measure} (in {self.error_unit})") + else: + raise ValueError(f"orientation must be `v' or `h' but is: {orientation}") text_box = AnchoredText(f"n={n_boots}", frameon=True, loc=4, pad=0.5) plt.setp(text_box.patch, edgecolor='k', facecolor='w') ax.add_artist(text_box) plt.setp(ax.lines, color='k') plt.tight_layout() self._save() + plt.close("all") if __name__ == "__main__":