MCPcopy Create free account
hub / github.com/RolnickLab/climart / prediction_bars

Function prediction_bars

climart/utils/plotting.py:365–405  ·  view source on GitHub ↗
(preds: dict, bins, TOA=False, surface=False,
                    title="", show=True, figsize=(16, 12), axes=None,
                    label="", **kwargs)

Source from the content-addressed store, hash-verified

363
364
365def prediction_bars(preds: dict, bins, TOA=False, surface=False,
366 title="", show=True, figsize=(16, 12), axes=None,
367 label="", **kwargs):
368 n_vars = len(preds.keys())
369 n_cols = 3 if TOA and surface else 2 if (TOA or surface) else 1
370
371 surface_ax = 1
372 TOA_ax = 2 if surface else 1
373
374 if axes is None:
375 fig, axs = plt.subplots(n_vars, n_cols, figsize=figsize)
376 fig.suptitle("Prediction magnitudes" if title == "" else title)
377 axs[0, 0].set_title('Mean')
378
379 if surface:
380 axs[0, surface_ax].set_title('Surface')
381 if TOA:
382 axs[0, TOA_ax].set_title('TOA')
383 else:
384 axs = axes
385
386 for i, ((var_name, var_preds), ax_row) in enumerate(zip(preds.items(), axs)):
387
388 if False: # i == 1:
389 kwargs['tick_label'] = ['{} - {}'.format(bins[i], bins[i + 1]) for i, j in enumerate(hist)]
390
391 hist, bin_edges = np.histogram(np.mean(var_preds, axis=1), bins)
392 ax_row[0].bar(range(len(hist)), hist, width=1, align='center', label=label, **kwargs)
393 ax_row[0].set_ylabel(f"{var_name.upper()}", fontsize=20)
394 if surface:
395 hist, bin_edges = np.histogram(var_preds[:, -1], bins)
396 ax_row[surface_ax].bar(range(len(hist)), hist, width=1, align='center', label=label, **kwargs)
397 if TOA:
398 hist, bin_edges = np.histogram(var_preds[:, 0], bins)
399 ax_row[TOA_ax].bar(range(len(hist)), hist, width=1, align='center', label=label, **kwargs)
400
401 axs[0, 0].legend()
402 if show:
403 plt.show()
404
405 return axs

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected