Skip to content

Add legend outside figure in plot_train#2164

Merged
shmh40 merged 18 commits intodevelopfrom
shmh40/dev/plot-train-legend
Apr 13, 2026
Merged

Add legend outside figure in plot_train#2164
shmh40 merged 18 commits intodevelopfrom
shmh40/dev/plot-train-legend

Conversation

@shmh40
Copy link
Copy Markdown
Contributor

@shmh40 shmh40 commented Apr 1, 2026

Description

Add a legend below figure in plot train.

Not well tested, not quite ready.

Issue Number

Closes #2200

Is this PR a draft? Mark it as draft.

Checklist before asking for review

  • I have performed a self-review of my code
  • My changes comply with basic sanity checks:
    • I have fixed formatting issues with ./scripts/actions.sh lint
    • I have run unit tests with ./scripts/actions.sh unit-test
    • I have documented my code and I have updated the docstrings.
    • I have added unit tests, if relevant
  • I have tried my changes with data and code:
    • I have run the integration tests with ./scripts/actions.sh integration-test
    • (bigger changes) I have run a full training and I have written in the comment the run_id(s): launch-slurm.py --time 60
    • (bigger changes and experiments) I have shared a hegdedoc in the github issue with all the configurations and runs for this experiments
  • I have informed and aligned with people impacted by my change:
    • for config changes: the MatterMost channels and/or a design doc
    • for changes of dependencies: the MatterMost software development channel

@shmh40 shmh40 self-assigned this Apr 1, 2026
Copy link
Copy Markdown
Collaborator

@clessig clessig left a comment

Choose a reason for hiding this comment

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

Thanks! See comments.

Comment thread config/evaluate/eval_config.yml Outdated
- fbi:
thresh: 280
- rmse
- rmse No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove change

Comment thread src/weathergen/utils/plot_training.py Outdated
half_len = (200 - len(plt_fname.suffix)) // 2
plt_fname = plt_fname.parent / (
plt_fname.name[:half_len]
+ "..."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please avoid .... On Linux systems . and .. are very special and having ... in a path/filename can lead to problems (both on human and system level).

Comment thread src/weathergen/utils/plot_training.py Outdated
if (min_val >= max_val) or np.isnan(min_val) or np.isnan(max_val):
continue

legend = plt.legend(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we have this here if _add_legend() is above?

"""
)

parser.add_argument(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am missing

    parser.add_argument(
        "--legend-outside",
        default=False,
        action="store_true",
        help="Legend outside of the plot",
    )

or similar here.

@clessig
Copy link
Copy Markdown
Collaborator

clessig commented Apr 13, 2026

@shmh40 : Could you have a look at this please

@shmh40 shmh40 requested a review from clessig April 13, 2026 10:17
@shmh40 shmh40 added the eval anything related to the model evaluation pipeline label Apr 13, 2026
@shmh40
Copy link
Copy Markdown
Contributor Author

shmh40 commented Apr 13, 2026

@shmh40 : Could you have a look at this please

Made changes and tested. Very many labels gives a mess without --legend-outside still, but this is expected.

@shmh40 shmh40 marked this pull request as ready for review April 13, 2026 10:20
Copy link
Copy Markdown
Collaborator

@clessig clessig left a comment

Choose a reason for hiding this comment

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

Just two minor comments

Comment thread src/weathergen/utils/plot_training.py Outdated
plt.savefig(plt_fname)
plt.savefig(plt_fname, bbox_inches="tight")
plt.close()
continue
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we need the continue here? It's at the end of all loopes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, left over

Comment thread src/weathergen/utils/plot_training.py Outdated
plt.xlabel("samples")
plt.tight_layout()
legend = _add_legend(legend_str, legend_outside=legend_outside)
for line in legend.get_lines():
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we add this to _add_legend()?

@shmh40 shmh40 merged commit f6f4818 into develop Apr 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eval anything related to the model evaluation pipeline

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Allow legend outside plot for plot_train

3 participants