From b3b69c79333d7d2636b04752e285f7ae2eba2c6a Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Thu, 12 May 2022 11:45:36 +0200 Subject: [PATCH] Plot histograms --- slr/get_slr_distributions.py | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/slr/get_slr_distributions.py b/slr/get_slr_distributions.py index a878a35..1755529 100644 --- a/slr/get_slr_distributions.py +++ b/slr/get_slr_distributions.py @@ -122,4 +122,42 @@ if PLOT: ax.spines['right'].set_visible(False) plt.show() +# Show histgrams with values clipped to our specific range +if PLOT: + for i, row in dff[::4].iterrows(): + fig, ax = plt.subplots(1, 1, figsize=(10, 2)) + + # Generate random samples in Cauchy distribution + r = stats.cauchy(loc=row['loc'], scale=row['scale']).rvs(1000000) + + # Clip to our range + x_min = row[5] + (row[5] - row[50]) + x_max = row[95] + (row[95] - row[50]) + rc = np.clip(r, a_min=x_min, a_max=x_max) + f = (r != rc).sum() / len(r) # Fraction outside range + + ax.hist(rc, 100) + + ym = ax.get_ylim()[1] # Maximum y value + + ax.axvline(x=x_min, c='C3') + ax.axvline(x=row[5], c='C3') + ax.axvline(x=row[50], c='C3') + ax.axvline(x=row[95], c='C3') + ax.axvline(x=x_max, c='C3') + + ax.annotate(' P0', (x_min, ym)) + ax.annotate(' P5', (row[5], ym)) + ax.annotate(' P50', (row[50], ym)) + ax.annotate(' P95', (row[95], ym)) + ax.annotate(' P100', (x_max, ym)) + + ax.annotate(f' Samples clipped = {100 * f:0.1f}%', (x_max, ym / 2)) + + ax.set_title(row.name, x=0) + ax.set_yticks([]) + ax.set_xlabel('SLR (m)', labelpad=10) + ax.spines['top'].set_visible(False) + ax.spines['right'].set_visible(False) + plt.show()