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.