Skip to main content

Functions to check Matplotlib plot outputs

Project description

DOI

MatPlotCheck

PyPI

codecov Documentation Status

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

[!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

Under Development

Matplotcheck is currently under significant development.

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!

Active Contributors

Peter Stenger

Contributors

We've welcome any and all contributions. Below are some of the contributors to MatPlotCheck.

Leah Wasser Nathan Korinek Ryan Larocque Kylen Solvik Kristen Curry

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

BSD-3

Citation Information

MatPlotCheck citation information can be found on zenodo. A link to bibtext format is below:

*bibtex

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matplotcheck2-0.2.0.tar.gz (45.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matplotcheck2-0.2.0-py3-none-any.whl (50.9 kB view details)

Uploaded Python 3

File details

Details for the file matplotcheck2-0.2.0.tar.gz.

File metadata

  • Download URL: matplotcheck2-0.2.0.tar.gz
  • Upload date:
  • Size: 45.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for matplotcheck2-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6f8acc94a71c6f903dec00e373d3f1ecaad96b2e209803b0c875d8423ce0d6e2
MD5 3d4f862e8388d1798b02cf4487159792
BLAKE2b-256 be2f2e0b89587825c4de8a9df2cde9472994a79f72e7e34b37bf2fd17fb4b768

See more details on using hashes here.

Provenance

The following attestation bundles were made for matplotcheck2-0.2.0.tar.gz:

Publisher: publish-pypi.yml on matplotcheck/matplotcheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file matplotcheck2-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: matplotcheck2-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 50.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for matplotcheck2-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0aacca464e061665cd457a0b23c433d646959abc64b7bfe8a07b1b3553020b5
MD5 e9359180c224aec6849c5a55c11b7d05
BLAKE2b-256 b0a1c7a5b120ec9bcbac6ab706eef154fa9c6087b56a4eb604f71d7e32f35d48

See more details on using hashes here.

Provenance

The following attestation bundles were made for matplotcheck2-0.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on matplotcheck/matplotcheck

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page