A network diagram with connected nodes, representing automated plot grading methods in CodeGrade.
June 25, 2025

Smarter Plot Grading in CodeGrade: Two Automated Approaches for Faster Feedback

In 30 seconds...

Tired of spending hours manually grading student plots? Discover two automated methods in CodeGrade – Image Comparison and Object Inspection – that provide fast, consistent feedback, freeing you up for more impactful teaching. Learn which approach is best for your data-heavy course.

Grading plots manually is one of the most time-consuming and inconsistent parts of teaching data-heavy courses. Whether students are visualizing model outputs, PCA projections, or the impact of changing parameters, you want to give meaningful feedback, without spending hours opening screenshots.

With CodeGrade, you can automatically grade student plots, giving them fast feedback and freeing yourself up for more impactful teaching.

In this post, we’ll walk through two flexible, fully automated ways to grade plots using CodeGrade’s Autotest system, and help you decide which fits your course best.

Method 1: Image Comparison

"Do the plots look the same?"

This setup allows you to automatically validate plots based on how closely they match the correct output in appearance, with no need to interpret data structures or inspect plot objects.

How it works:

A grading script compares the student’s plot with a reference image using the Structural Similarity Index (SSIM) — a perceptual image quality metric provided by the scikit-image library.

Here’s what the script does:

  • Loads both the student’s and reference images using Pillow

  • Converts the images to grayscale and NumPy arrays for consistency

  • Calculates an SSIM score to measure visual similarity

  • Passes the test if the score is high enough (typically above 0.80)

This is a great fit for assignments where visual output matters most — such as scatter plots, PCA projections, or clustering visualizations — and you're looking for quick confirmation that the student produced a similar-looking plot.

Best for: fast visual checks, cosmetic layout validation, quick setup
Keep in mind: it’s sensitive to small changes like font size or resolution, and it doesn’t check if the right data was plotted — only how it looks. It also requires managing external plot files in the fixture folder.

Start grading your plots today!

Method 2: Object-Based Plot Inspection

"Did they plot the right data in the right way?"

This method goes deeper. Instead of comparing images, it inspects the actual matplotlib objects created by the student, checking for things like titles, labels, plotted data, and legends.

Best of all: it all runs inline using CodeGrade’s Run in Notebook block — no external files required.

How it works:

A key part of this setup is a custom monkeypatching script that temporarily overrides matplotlib.pyplot.figure and plt.show. This lets you intercept and inspect all plots programmatically.

Here’s what the patch does:

  • Captures every figure created, so they can be accessed after plotting

  • Prevents plt.show() from blocking the test (since it runs in a headless environment)

  • Clears figures after showing, just like in a regular plotting session

This makes it possible to write tests that assert:

  • If a title, x/y labels, and legend exist

  • If the correct number of lines or data points are plotted

  • If the plotted values match an expected result (using NumPy comparison)

It’s precise, reusable, and gives you full control, making it perfect for assignments focused on interpreting or validating data.

Best for: verifying structure, data correctness, scientific plotting
Keep in mind: it requires matplotlib, and a little upfront scripting (which you can reuse across assignments).

Okay, I understand. Here's the updated text with the bullet points no longer in bold, making it look cleaner and less visually heavy:

Which Method Should You Use?

Here's a guide to help you choose the right method based on your needs:

If you care about...

  • Matching appearance closely:
    • Use the Image Comparison method.
  • Verifying structure and data correctness:
    • Use the Object Inspection method.
  • Avoiding file management:
    • Use the Object Inspection method.
  • Fast visual checks at scale:
    • Use the Image Comparison method.
  • Detailed feedback on plotting conventions:
    • Use the Object Inspection method.

Combining Both Methods:You can also combine both methods for comprehensive testing:

  • Use Object Inspection to validate correctness and structure.
  • Use Image Comparison to catch visual styling issues.

Manual Plot Grading

If students use non-standard plotting libraries like Plotly, Bokeh, or create highly customized plots, automated grading might not cover everything.

CodeGrade makes it easy to grade these manually:

  • Students save plots using plt.savefig(...)

  • Use Output block to show saved plots in the Autotest output panel, right alongside their code and answers
  • You assign points using a rubric and leave feedback as needed

This gives you the flexibility to still assess creative visualizations while maintaining consistency and clarity in grading.

Plot grading doesn’t have to be slow or vague. Start with one method, combine both, or adapt them to your own course, and make grading smarter, faster, and more accurate.

Continue reading

Hands-On Python for Engineering Applications at Ferris State

See how Ferris State teaches practical programming, data analysis, and automation, building student confidence and skills for their future careers.

How to auto-grade Jupyter Notebooks

Simplify grading Jupyter Notebooks. Learn what is Jupyter Notebook and how to use CodeGrade for easy auto-grading. Streamline how to submit Jupyter Notebook assignment for faster student feedback.

Automatic Submission Testing for R Programming: A Project from Wageningen University

Discover how Wageningen University used CodeGrade to automate R assignment testing, speeding up feedback and improving learning outcomes at scale.

Sign up to our newsletter