Skip to content
Snippets Groups Projects
Commit 549ffe89 authored by Felix Kleinert's avatar Felix Kleinert
Browse files

include horizontal version of PlotSampleUncertaintyFromBootstrap

parent 8d343f1b
Branches
Tags
7 merge requests!353add developments to release v1.5.0,!352Resolve "release v1.5.0",!351Lukas issue337 bug ci pipeline fails for docs,!350Resolve "upgrade code to TensorFlow V2",!342Include sample-uncertainty to wrf workflow,!337Resolve "Test Set Sample Uncertainty in PostProcessing",!259Draft: Resolve "WRF-Datahandler should inherit from SingleStationDatahandler"
Pipeline #80981 passed
......@@ -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)
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__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment