Skip to main content

Functions to check Matplotlib plot outputs

Project description

DOI

MatPlotCheck

PyPI PyPI - Downloads Conda Conda

Build Status Build status codecov Documentation Status Code style: black

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 either pip or conda. To use pip run:

pip install --upgrade matplotcheck

To use conda: conda install -c conda-forge matplotcheck

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

Leah Wasser Nathan Korinek

Contributors

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

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

matplotcheck-0.1.4.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

matplotcheck-0.1.4-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file matplotcheck-0.1.4.tar.gz.

File metadata

  • Download URL: matplotcheck-0.1.4.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for matplotcheck-0.1.4.tar.gz
Algorithm Hash digest
SHA256 762d5365e51c3d73de1b4ebfb5c52a423885fba2dc2054a1f1319fc40db3b896
MD5 8f2a3efbc4a90847be3a2b515bb9a1ab
BLAKE2b-256 3c649de5cb50eb1a51a8874a7d2c51e984577a9ffd4099385d4483b9caa779e3

See more details on using hashes here.

File details

Details for the file matplotcheck-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: matplotcheck-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for matplotcheck-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e25704c8959eb99bb30cb7f6b353da956f38532e42929fbac725c5e1edac2954
MD5 9ef839484c2649c0e731b74b85ae307b
BLAKE2b-256 4143e0d7efb953f0d5a4f5b8fd2727b6cec968568135fd7c4d5b5d86a1d51571

See more details on using hashes here.

Supported by

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