diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py index 1e3ce12638b6433fe7283769ac353d2e8579618e..8d7bfd0c37966b623f99ac72f316e36aa241dd3b 100644 --- a/mlair/plotting/postprocessing_plotting.py +++ b/mlair/plotting/postprocessing_plotting.py @@ -900,6 +900,9 @@ class PlotBootstrapSkillScore(AbstractPlotClass): data_first = self._select_data(df=data, variables=separate_vars, column_name='boot_var') data_second = self._select_data(df=data, variables=remaining_vars, column_name='boot_var') + order_first = self.set_order_for_x_axis(separate_vars) + order_second = self.set_order_for_x_axis(remaining_vars) + fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(len(self._individual_vars) / 2, 10), gridspec_kw={'width_ratios': [len(separate_vars), @@ -913,13 +916,13 @@ class PlotBootstrapSkillScore(AbstractPlotClass): first_box_width = 2. sns.boxplot(x=self._x_name, y="data", hue="ahead", data=data_first, ax=ax[0], whis=1., palette="Blues_d", - showmeans=True, meanprops={"markersize": 1, "markeredgecolor": "k"}, + showmeans=True, order=order_first, meanprops={"markersize": 1, "markeredgecolor": "k"}, flierprops={"marker": "."}, width=first_box_width ) ax[0].set(ylabel=f"skill score", xlabel="") sns.boxplot(x=self._x_name, y="data", hue="ahead", data=data_second, ax=ax[1], whis=1., palette="Blues_d", - showmeans=True, meanprops={"markersize": 1, "markeredgecolor": "k"}, + showmeans=True, order=order_second, meanprops={"markersize": 1, "markeredgecolor": "k"}, flierprops={"marker": "."}, ) ax[1].set(ylabel="", xlabel="") @@ -984,12 +987,16 @@ class PlotBootstrapSkillScore(AbstractPlotClass): """ number_of_vars = len(self._individual_vars) + order = self.set_order_for_x_axis(self._individual_vars) + + if number_of_vars > 20: fig, ax = plt.subplots(figsize=(number_of_vars/2, 10)) else: fig, ax = plt.subplots() sns.boxplot(x=self._x_name, y="data", hue="ahead", data=self._data, ax=ax, whis=1., palette="Blues_d", - showmeans=True, meanprops={"markersize": 1, "markeredgecolor": "k"}, flierprops={"marker": "."}) + showmeans=True, meanprops={"markersize": 1, "markeredgecolor": "k"}, flierprops={"marker": "."}, + order=order) ax.axhline(y=0, color="grey", linewidth=.5) plt.xticks(rotation=45, horizontalalignment="right") ax.set(ylabel=f"skill score", xlabel="", title="summary of all stations") @@ -997,6 +1004,28 @@ class PlotBootstrapSkillScore(AbstractPlotClass): ax.legend(handles, self._labels) plt.tight_layout() + @staticmethod + def set_order_for_x_axis(var_list, sect_split_name="Sect"): + try: + split_names = [i.split(sect_split_name) for i in var_list] + center_name = [] + sector_identifier = [] + for i in split_names: + if len(i) == 1: + center_name += i + else: + sector_identifier.append(i[1]) + center_name = sorted(center_name) + sector_identifier = sorted(list(set(sector_identifier))) + new_order = [] + for center in center_name: + new_order += [center] + [center+sect_split_name+sec for sec in sector_identifier] + except: + new_order = None + + return new_order + + @TimeTrackingWrapper class PlotTimeSeries: