Skip to content

Add feedback.add_image to show plots with test results - #42

Merged
eliotwrobson merged 1 commit into
mainfrom
claude/feedback-images
Nov 11, 2026
Merged

eliotwrobson merged 1 commit into
mainfrom
claude/feedback-images

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

The legacy grader showed students their plot with the grading results. This grader had no way to return an image, so plot questions lost that feedback.

feedback.add_image(image, label=None) takes a matplotlib Figure or Axes, such as a plot queried from student code, or PNG bytes. It adds the image to the test's images in results.json, which <pl-external-grader-results> shows under the test. A plot is drawn as a PNG from the Figure that the grader rebuilt from the student's plot. matplotlib is only imported when a plot is passed, so the :lite image still works without it.

quick_start.md documents it in a new "Showing Plots to Students" section. That file conflicts with the rewrite in #38, so I'll move the section over to whichever of the two merges second.

Testing

  • Unit tests in tests/test_feedback.py decode each image and check for the PNG signature.
  • The test_plain_matplotlib scenario adds a queried plot to the results. The scenario runner now checks image labels and data URL prefixes. It doesn't compare PNG bytes, because those depend on the matplotlib version.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eliotwrobson added a commit to PrairieLearn/PrairieLearn that referenced this pull request Nov 11, 2026
Uses feedback.add_image from PrairieLearn/grader-python-v2#42, which needs to be published before this merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 11, 2026 17:13
@eliotwrobson
eliotwrobson merged commit 3126734 into main Nov 11, 2026
5 checks passed
eliotwrobson added a commit that referenced this pull request Nov 12, 2026
Move the plot docs from #32, #42 and #43 into the restructured
quick_start.md, and update the conversion guide now that plot questions
can be converted with assert_plot_equal and feedback.add_image.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Victorsss-Orz pushed a commit to Victorsss-Orz/PrairieLearn that referenced this pull request Nov 16, 2026
* Convert plots Python question to pytest grader

Student code now builds the plot with MatplotlibSerializer, because a plain
matplotlib axes can't be sent back to the grader. The test makes the same checks
as the legacy check_plot: axis scales, line count, and line data within
tolerance.

Set a longer sandbox timeout, because importing matplotlib in student code can
take longer than the 1 second default on a busy host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Use plain matplotlib in the plots question

Grader v1.2.0 accepts plain matplotlib Axes and Figure values and no
longer includes plot-serializer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show the student's plot with the plots question's results

Uses feedback.add_image from PrairieLearn/grader-python-v2#42, which needs to be published before this merges.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Describe the pytest grader's plot interface in the plots question

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the plots question with assert_plot_equal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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