Skip to content

Support text, annotations, axhline and axvline in plots, and fix a startup timeout race - #44

Draft
eliotwrobson wants to merge 2 commits into
mainfrom
claude/plot-text
Draft

eliotwrobson wants to merge 2 commits into
mainfrom
claude/plot-text

Conversation

@eliotwrobson

@eliotwrobson eliotwrobson commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

A correct plot that also has plt.text(...) is currently rejected when it's sent to the test, so the student scores 0 with "text and annotations aren't supported". A review comment on PrairieLearn/PrairieLearn#16284 found this. axhline and axvline, which students often use for reference lines, are rejected the same way.

  • Sent to the test:
    • text in data or axes coordinates, with its alignment and rotation.
    • annotate, with its point in data or axes coordinates, its text position in data or axes coordinates or offset points, and whether it has an arrow. Every arrow comes back as a plain -> arrow.
    • axhline and axvline, with their position, extent, label, color, width and style. A line is treated as one only if it uses their blended transform and has a constant value, so other blended lines are still rejected.
    • Text in figure coordinates, axline, errorbar and fill_between are still rejected.
  • assert_plot_equal:
    • axhline and axvline lines are compared as their own kinds, with the same rules as other lines.
    • The new check_texts option, off by default, compares the strings of text and annotations, and the point each annotation points at. The position of plain text isn't compared.
    • Extra text never fails a comparison unless check_texts is on, which covers the review comment's case.
  • Startup timeout race: the start response was read with the same timeout the sandbox used for the student code, so a slow submission got either "Student code initialization timed out" or "No response from initialization" at random. This made test_timeout flaky. The read now waits an extra 0.5 seconds, so the sandbox's own message is reported. "No response" is now only for a sandbox that doesn't answer at all.

Testing

With an image built from this branch, the converted plots question gives:

Submission Score
Starter code plus plt.text 1.0
Starter code plus annotate with an arrow 1.0
Starter code plus axhline 0.0: Expected 0 horizontal lines in your plot, but found 1.

The axhline result is intended: extra lines fail unless the test sets allow_extra. In all three cases, the image shown with the results matched the student's plot.

The timeout scenarios failed about 1 run in 12 before the race fix, and passed 40 runs in a row after it.

🤖 Generated with Claude Code

eliotwrobson and others added 2 commits November 13, 2026 17:23
Plain text and annotations in data or axes coordinates, and lines from
axhline and axvline, are now sent to the test instead of rejecting the
whole plot. assert_plot_equal compares the new lines with the other data,
and a new check_texts option compares text and annotations. Extra text is
ignored unless check_texts is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parent read the start response with the same timeout the sandbox used for
the student code, so a slow submission got either message at random. Wait a
little longer so the sandbox's timeout response arrives first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliotwrobson eliotwrobson changed the title Support text, annotations, axhline and axvline in plots Support text, annotations, axhline and axvline in plots, and fix a startup timeout race Nov 14, 2026
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