MatPlotCheck
A package for testing different types of matplotlib plots including:
- basic matplotlib plots
- geopandas spatial vector plots
- raster plots
- time series plots
- folium plots
and more!
Why MatPlotCheck?
There is often a need to test plots particularly when teaching data science courses. The Matplotlib api can be complex to navigate when trying to write tests. MatPlotCheck was developed to make it easier to test data, titles, axes and other elements of Matplotlib plots in support of both autograding and other testing needs.
MatPlotCheck was inspired by plotChecker developed by Jess Hamrick.
We spoke with her about our development and decided to extend plotChecker to suite some of the grading needs in our classes which include plots with spatial data using numpy for images and geopandas for vector data.
Install MatPlotCheck
You can install MatPlotCheck using pip. To use pip run:
pip install --upgrade matplotcheck2
For additional functionality, you can install optional dependencies:
# For spatial/vector plotting checks (geopandas, shapely)
pip install matplotcheck2[spatial]
# For time series plotting checks with regression lines (scipy, python-dateutil)
pip install matplotcheck2[timeseries]
# For folium map checks
pip install matplotcheck2[folium]
# Install all optional dependencies
pip install matplotcheck2[all]
[!NOTE]
This fork takes over the original matplotcheck package. The original package is no longer maintained and will not be updated. See https://github.com/earthlab/matplotcheck/pull/429
To import it into Python:
import matplotcheck as mpc
Examples
2D plot with x-axis label containing "x" and y-axis label containing "y" and "data"
from matplotcheck.cases import PlotBasicSuite
import pandas as pd
import unittest
axis = plt.gca()
data = pd.DataFrame(data={"x":xvals, "y":yvals})
suite = PlotBasicSuite(ax=axis, data_exp=data, xcol="x", ycol="y")
xlabel_contains=["x"], ylabel_contains = ["y","data"])
results = unittest.TextTestRunner().run(suite)
Example Plot with Spatial Raster Data
Plot containing a spatial raster image and spatial polygon vector data
from matplotcheck.cases import PlotRasterSuite
axis = plt.gca()
suite = PlotRasterSuite(ax=axis, im_expected=image, polygons=polygons)
results = unittest.TextTestRunner().run(suite)
If you prefer to forgo the groupings into TestSuites, you can just use the assertions instead.
2D plot with x-axis label containing "x" and y-axis label containing "y" and "data"
from matplotcheck.base import PlotTester
import pandas as pd
axis = plt.gca()
pt = PlotTester(axis)
data = pd.DataFrame(data={"x":xvals, "y":yvals})
pt.assert_xydata(data, "x", "y")
pt.assert_xlabel_contains(["x"])
pt.assert_ylabel_contains(["y", "data"])
Plot containing a spatial raster image and spatial polygon vector data
from matplotcheck.raster import RasterTester
from matplotcheck.vector import VectorTester
axis = plt.gca()
rt = RasterTester(axis)
vt = VectorTester(axis)
rt.assert_image(im_expected=image)
vt.assert_polygons(polygons_expected=polygons)
Caveats: This repo likely misses edge cases of the many ways matplotlib plots can be created. Please feel free to submit bugs!
Documentation
Documentation is available at matplotcheck2.readthedocs.io.
Active Contributors
Contributors
We've welcome any and all contributions. Below are some of the contributors to MatPlotCheck.
How to Contribute
We welcome contributions to MatPlotCheck! Please be sure to check out our contributing guidelines for more information about submitting pull requests or changes to MatPlotCheck.
License & Citation
Citation Information
MatPlotCheck citation information can be found on zenodo. A link to bibtext format is below:
Metadata
Release files for matplotcheck2 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| matplotcheck2-0.2.1.tar.gz | 46.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| matplotcheck2-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 98.9 kB
Release files / matplotcheck2-0.2.1.tar.gz
| Download URL | matplotcheck2-0.2.1.tar.gz |
|---|---|
| Size | 46.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aff869144e72e98eb8f7d6af240b6534ca33aafbecb69a8de2d875f482f2080b
|
|
BLAKE2b-256 checksum How to use checksums |
ff03d79cfd4114046d50d4dc45788458684f4c1e3a435b4045269995c8147ddd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 29, 2025.
Transparency logRelease files / matplotcheck2-0.2.1-py3-none-any.whl
| Download URL | matplotcheck2-0.2.1-py3-none-any.whl |
|---|---|
| Size | 52.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f27684041c302ee6a43894ac06baefb889b828305998553a63e0b36cbb99213
|
|
BLAKE2b-256 checksum How to use checksums |
ed667fa0d6368c556d4e5fad6f73cedb47b768c25b57611c5ef1bbc73ef56216
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 29, 2025.
Transparency log