Repository navigation
Add a deterministic figure layout check (scripts/figcheck.py) - #41
Merged
Merged
Conversation
assert_layout(fig) raises when two visible text labels overlap or sit closer than 3 pt, or when a legend covers a data point, so a crowded figure fails the notebook and the pipeline instead of reaching the Jupyter Book. spread_labels() places direct line labels with the minimum separation. The 04_figures scaffold calls the check before savefig; cicd-conventions documents it. Tests in tests/test_figcheck.py. Developed in annefou/logrono-flood-adaptation-scenarios, where it caught a legend over data, crowded line labels and labels running into the next panel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
scripts/figcheck.pychecks a rendered matplotlib figure and raises when:Because
assert_layout(fig)raises, a crowded figure fails the notebook and the Snakemake rule (locally and in CI) instead of reaching the Jupyter Book. A helper,spread_labels(ax, [(x, y, text), ...]), places direct labels at the end of lines with the minimum separation.Changes
scripts/figcheck.pylayout_problems,assert_layout,spread_labelstests/test_figcheck.pyspread_labelsseparates close labels)notebooks/04_figures.pyassert_layout(fig)beforesavefigdocs/cicd-conventions.mdThe template's full test suite passes (178 tests).
Why
Figure problems (labels on top of each other, a legend hiding data, direct labels running into the next panel) do not fail a pipeline today; they are found by eye or not at all. Developed in annefou/logrono-flood-adaptation-scenarios, where it caught all three in real figures.
Scope
Layout only. It does not judge whether a chart is the right one or whether its colours are distinguishable for colour-vision deficiencies: still look at the output.
🤖 Generated with Claude Code