From 0966d8e30b8b4d18fb2619da2ee7ca707d8e10e0 Mon Sep 17 00:00:00 2001
From: Felix Kleinert <f.kleinert@fz-juelich.de>
Date: Mon, 22 Aug 2022 08:23:49 +0200
Subject: [PATCH] update rank hist plot

---
 mlair/plotting/postprocessing_plotting.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py
index 7034c513..68f82a77 100644
--- a/mlair/plotting/postprocessing_plotting.py
+++ b/mlair/plotting/postprocessing_plotting.py
@@ -1333,11 +1333,14 @@ class PlotRankHistogram(AbstractPlotClass):
             pdf_pages = matplotlib.backends.backend_pdf.PdfPages(plot_path)
             for ah in value[self.ahead_dim]:
                 fig, ax = plt.subplots()
-                ax.bar(value.sel({"rank_hist_type": "bins", self.ahead_dim: ah.values}),
-                       value.sel({"rank_hist_type": "freq", self.ahead_dim: ah.values}),
-                       align='center')
-                ax.set_xlabel(f"{self.target_var} (in {self.target_unit})")
-                ax.set_ylabel("freq")
+                bins = value.sel({"rank_hist_type": "bins", self.ahead_dim: ah.values})
+                freq = value.sel({"rank_hist_type": "freq", self.ahead_dim: ah.values})
+                relfreq = freq/freq.sum()
+                ax.bar(bins, relfreq, align='center', color="gray")
+                ax.hlines(1. / len(bins), 0, len(bins), color="black", linestyle="dashed")
+                ax.set_xlabel(r"Verification Rank ($n_{ens}+1$)")
+                ax.set_ylabel("Relative Frequency")
+
                 plt.title(f"{ah.values}")
                 pdf_pages.savefig()
                 plt.close('all')
-- 
GitLab