Skip to content

Add assert_plot_equal to compare a plot with a reference plot - #43

Merged
eliotwrobson merged 2 commits into
mainfrom
claude/assert-plot-equal
Nov 11, 2026
Merged

eliotwrobson merged 2 commits into
mainfrom
claude/assert-plot-equal

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Adds assertions.assert_plot_equal(plot, expected, ...), a replacement for the legacy grader's Feedback.check_plot.

  • Default checks: the number of subplots, the axis scales, and the data in lines, scatter plots and bar plots, compared with numpy.allclose. Series can be in any order. A line also matches with its points reversed, but not scrambled. Scatter points and bars can be in any order.
  • Options: ordered, allow_extra, and opt-in check_labels, check_titles, check_legend, check_limits and check_styles. check_scales and check_data can be turned off.
  • Messages: a failure names the first difference, such as Expected a log scale on the y-axis of your plot, but found a linear scale. name and msg customize the message.
  • Optional import: the comparison lives in plot_checks.py, which assertions imports only when the function is called. A new test imports the plugin, assertions and fixture with matplotlib and numpy blocked.
  • Legacy bugs not carried over: check_plot printed the list of lines instead of the expected count. Its point sort also went along the wrong axis.

Unit tests cover each check, the failure messages, and a plot rebuilt from the sandbox's JSON with every check turned on. The test_plain_matplotlib scenario adds a passing check and a failing one with friendly output. Documented in quick_start.md under "Comparing with a Reference Plot".

🤖 Generated with Claude Code

eliotwrobson and others added 2 commits November 11, 2026 14:00
It replaces the legacy grader's Feedback.check_plot. By default it compares
the number of subplots, axis scales, and line, scatter and bar data, with
options to check labels, titles, legends, limits and styles, require order,
or allow extra series. matplotlib is still imported only when a plot is
checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Also remove a matched series by position instead of with list.remove,
which compared series with == and raised for two lines with the same
label.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 11, 2026 19:20
@eliotwrobson
eliotwrobson merged commit 70173c9 into main Nov 11, 2026
5 checks passed
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.

1 participant