Skip to content

Conversation

jpalm3r
Copy link
Contributor

@jpalm3r jpalm3r commented Sep 20, 2024

Previously, by default, the x positions of the skill plots were at [1, 2, 3, ..., n]. However, when an aux variable is numeric, that raised rendering issues (see issue #429).

This PR changes the handling of x labels in skill plots based on whether the x values are numeric or not.

@jpalm3r jpalm3r added the bug Something isn't working label Sep 20, 2024
@jpalm3r jpalm3r requested a review from ecomodeller September 20, 2024 15:11
Copy link
Member

@jsmariegaard jsmariegaard left a comment

Choose a reason for hiding this comment

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

Looks great - and I can confirm it works.

But could you please update the notebook "" to use this functionality :-)

You could change the cell

def _format_ax(ax, xlims, ylims):
    ax.set_xlim(*xlims)
    ax.set_ylim(*ylims)
    ax.set_xlabel("Lead time [days]", fontsize=12)
    ax.set_ylabel("MAPE [%]", fontsize=12)
    ax.legend(frameon=False, fontsize=12, bbox_to_anchor=(1.25, 0.7)),
    ax.tick_params(axis="both", which="major", labelsize=12)
    ax.set_title("Skill by lead time")
    ax.figure.autofmt_xdate(rotation=0, ha='center')
    
fig, ax = plt.subplots(1, 1, figsize=(8, 5))
sk.mape.plot.line(ax=ax, color=my_color_dict)
_format_ax(ax, xlims=(0, 7), ylims=(0, 10))
plt.show()

to something like

sk.mape.plot.line(title="Skill by lead time")

So at we would have at least one "example" of this :-)

@jpalm3r
Copy link
Contributor Author

jpalm3r commented Sep 23, 2024

I do not understand.

This _format_ax() function in the notebook has nothing to do with the bug fixed in this PR. I created that function to consistently format all plots in my notebook.

If I implement sk.mape.plot.line(ax=ax, color=my_color_dict), then I get:

image

Which was already correct before the PR, since the lead time has a time step = 1. However, I wanted it a bit "prettier", so I made the formatting function.

Copy link
Member

@jsmariegaard jsmariegaard left a comment

Choose a reason for hiding this comment

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

Got it. Let's merge

@jsmariegaard jsmariegaard merged commit c6e0890 into main Sep 23, 2024
7 checks passed
@jpalm3r jpalm3r deleted the plot_by_aux_variable branch September 23, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants