Spaces:
Runtime error
Runtime error
Commit
·
e52c4aa
1
Parent(s):
adcaa7a
add CRPS plot
Browse files- temps/plots.py +52 -0
temps/plots.py
CHANGED
@@ -281,3 +281,55 @@ def plot_nz(df_list, zcuts = [0.1, 0.5, 1, 1.5, 2, 3, 4]):
|
|
281 |
plt.savefig(f'nz_hist.pdf', dpi=300, bbox_inches='tight')
|
282 |
|
283 |
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
plt.savefig(f'nz_hist.pdf', dpi=300, bbox_inches='tight')
|
282 |
|
283 |
plt.show()
|
284 |
+
|
285 |
+
|
286 |
+
|
287 |
+
|
288 |
+
def plot_crps(crps_list_1, crps_list_2 = None, crps_list_3=None, labels=None, sample='specz', save =True):
|
289 |
+
# Create a figure and axis
|
290 |
+
#plot properties
|
291 |
+
plt.rcParams['font.family'] = 'serif'
|
292 |
+
plt.rcParams['font.size'] = 12
|
293 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
294 |
+
cmap = plt.get_cmap('Dark2')
|
295 |
+
|
296 |
+
kwargs=dict(bins=50, histtype='step', density=True, range=(0,1))
|
297 |
+
|
298 |
+
# Create a histogram
|
299 |
+
hist, bins, _ = ax.hist(crps_list_1, color=cmap(0), ls='--', **kwargs, label=labels[0])
|
300 |
+
if crps_list_2 is not None:
|
301 |
+
hist, bins, _ = ax.hist(crps_list_2, color=cmap(1), ls=':', **kwargs, label=labels[1])
|
302 |
+
if crps_list_3 is not None:
|
303 |
+
hist, bins, _ = ax.hist(crps_list_3, color=cmap(2), ls='-', **kwargs, label=labels[2])
|
304 |
+
|
305 |
+
# Add labels and a title
|
306 |
+
ax.set_xlabel('CRPS Scores', fontsize = 18)
|
307 |
+
ax.set_ylabel('Frequency', fontsize = 18)
|
308 |
+
|
309 |
+
# Add grid lines
|
310 |
+
ax.grid(True, linestyle='--', alpha=0.7)
|
311 |
+
|
312 |
+
# Customize the x-axis
|
313 |
+
ax.set_xlim(0, 0.5)
|
314 |
+
|
315 |
+
# Make ticks larger
|
316 |
+
ax.tick_params(axis='both', which='major', labelsize=14)
|
317 |
+
|
318 |
+
# Calculate the mean CRPS value
|
319 |
+
mean_crps_1 = round(np.nanmean(crps_list_1), 2)
|
320 |
+
mean_crps_2 = round(np.nanmean(crps_list_2), 2)
|
321 |
+
mean_crps_3 = round(np.nanmean(crps_list_3), 2)
|
322 |
+
|
323 |
+
|
324 |
+
# Add the mean CRPS value at the top-left corner
|
325 |
+
ax.annotate(f"Mean CRPS {labels[0]}: {mean_crps_1}", xy=(0.57, 0.9), xycoords='axes fraction', fontsize=14, color =cmap(0))
|
326 |
+
ax.annotate(f"Mean CRPS {labels[1]}: {mean_crps_2}", xy=(0.57, 0.85), xycoords='axes fraction', fontsize=14, color =cmap(1))
|
327 |
+
ax.annotate(f"Mean CRPS {labels[2]}: {mean_crps_3}", xy=(0.57, 0.8), xycoords='axes fraction', fontsize=14, color =cmap(2))
|
328 |
+
|
329 |
+
|
330 |
+
if save==True:
|
331 |
+
plt.savefig(f'{sample}_CRPS.pdf', bbox_inches='tight')
|
332 |
+
|
333 |
+
# Show the plot
|
334 |
+
plt.show()
|
335 |
+
|