Skip to content

add function for violin plot nr of obs vs err#61

Open
rogerkuou wants to merge 1 commit into
mainfrom
violin_plot
Open

add function for violin plot nr of obs vs err#61
rogerkuou wants to merge 1 commit into
mainfrom
violin_plot

Conversation

@rogerkuou

Copy link
Copy Markdown
Collaborator

Add a function plotting violin plot. Example as following

image

@rogerkuou rogerkuou requested a review from SarahAlidoost June 23, 2026 14:28
Comment thread climanet/utils.py
The three inputs are expected to be xarray DataArrays with dimensions (time, lat, lon).
They should share the same spatial and temporal coordinates.

Parameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using Args and Return for docstring style in most of the source codes.

Comment thread climanet/utils.py
axes = [axes]

for i, ax in enumerate(axes):
ax.set_title(f"Month = {i}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use actual time info for title as: err_baseline.time.dt.strftime('%Y-%m-%d').values[t]

Comment thread climanet/utils.py
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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
n_obs_unique = np.unique(nobs.isel(time=i).values.flatten())
n_obs_unique = np.unique(nobs.isel(time=i).values)

Comment thread climanet/utils.py

# 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)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)]

Comment thread climanet/utils.py
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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
n_obs_unique = n_obs_unique[n_obs_unique > 0]

Comment thread climanet/utils.py
err_by_n_obs_baseline = []
err_by_n_obs_predictions = []

for n_obs in n_obs_unique:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n_obs is the input argument of the function. Please choose another variable name in the loop.

Comment thread climanet/utils.py
h["cmaxes"].set_alpha(0.2)

ax.set_xlabel("Number of Daily Observations")
ax.set_ylabel("Log Absolute Error (K)")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax.set_ylabel("Log Absolute Error (K)")
ax.set_ylabel("Symmetric log-scaled Absolute Error (K)")

Comment thread climanet/utils.py
loc="upper right",
)

plt.tight_layout()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
plt.tight_layout()
plt.tight_layout()

Comment thread climanet/utils.py
h["cmaxes"].set_linewidth(0.35)
h["cmaxes"].set_alpha(0.2)

ax.set_xlabel("Number of Daily Observations")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ax.set_xlabel("Number of Daily Observations")
ax.set_xlabel("Number of Observations")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function work for hourly data too?

@SarahAlidoost SarahAlidoost left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rogerkuou Thanks! just minor comments, after addressing them, this PR can be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants