add function for violin plot nr of obs vs err#61
Conversation
| The three inputs are expected to be xarray DataArrays with dimensions (time, lat, lon). | ||
| They should share the same spatial and temporal coordinates. | ||
|
|
||
| Parameters |
There was a problem hiding this comment.
We are using Args and Return for docstring style in most of the source codes.
| axes = [axes] | ||
|
|
||
| for i, ax in enumerate(axes): | ||
| ax.set_title(f"Month = {i}") |
There was a problem hiding this comment.
Please use actual time info for title as: err_baseline.time.dt.strftime('%Y-%m-%d').values[t]
| ax.set_title(f"Month = {i}") | ||
|
|
||
| # Get unique number of observations for this month, ignoring NaNs and zeros | ||
| n_obs_unique = np.unique(nobs.isel(time=i).values.flatten()) |
There was a problem hiding this comment.
| n_obs_unique = np.unique(nobs.isel(time=i).values.flatten()) | |
| n_obs_unique = np.unique(nobs.isel(time=i).values) |
|
|
||
| # Get unique number of observations for this month, ignoring NaNs and zeros | ||
| n_obs_unique = np.unique(nobs.isel(time=i).values.flatten()) | ||
| n_obs_unique = n_obs_unique[~np.isnan(n_obs_unique)] |
There was a problem hiding this comment.
| n_obs_unique = n_obs_unique[~np.isnan(n_obs_unique)] | |
| n_obs_unique = n_obs_unique[(~np.isnan(n_obs_unique)) & (n_obs_unique > 0)] |
| n_obs_unique = np.unique(nobs.isel(time=i).values.flatten()) | ||
| n_obs_unique = n_obs_unique[~np.isnan(n_obs_unique)] | ||
| n_obs_unique = n_obs_unique.astype(int) | ||
| n_obs_unique = n_obs_unique[n_obs_unique > 0] |
There was a problem hiding this comment.
| n_obs_unique = n_obs_unique[n_obs_unique > 0] |
| err_by_n_obs_baseline = [] | ||
| err_by_n_obs_predictions = [] | ||
|
|
||
| for n_obs in n_obs_unique: |
There was a problem hiding this comment.
n_obs is the input argument of the function. Please choose another variable name in the loop.
| h["cmaxes"].set_alpha(0.2) | ||
|
|
||
| ax.set_xlabel("Number of Daily Observations") | ||
| ax.set_ylabel("Log Absolute Error (K)") |
There was a problem hiding this comment.
| ax.set_ylabel("Log Absolute Error (K)") | |
| ax.set_ylabel("Symmetric log-scaled Absolute Error (K)") |
| loc="upper right", | ||
| ) | ||
|
|
||
| plt.tight_layout() |
There was a problem hiding this comment.
| plt.tight_layout() | |
| plt.tight_layout() |
| h["cmaxes"].set_linewidth(0.35) | ||
| h["cmaxes"].set_alpha(0.2) | ||
|
|
||
| ax.set_xlabel("Number of Daily Observations") |
There was a problem hiding this comment.
| ax.set_xlabel("Number of Daily Observations") | |
| ax.set_xlabel("Number of Observations") |
There was a problem hiding this comment.
Does this function work for hourly data too?
SarahAlidoost
left a comment
There was a problem hiding this comment.
@rogerkuou Thanks! just minor comments, after addressing them, this PR can be merged.
Add a function plotting violin plot. Example as following