Skip to main content

Functions to check and validate elements in a matplotlib created python plot.

Project description

![Build Status](https://travis-ci.com/earthlab/matplotcheck.svg?branch=master)
![codecov](https://codecov.io/gh/earthlab/matPlotCheck/branch/master/graph/badge.svg)
![Documentation Status](https://readthedocs.org/projects/matplotcheck/badge/?version=latest)
![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)

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


## Install

To install, use pip. `--upgrade` is optional but it ensures that the package overwrites
when you install and you have the current version. If you don't have the package
yet you can still use the `--upgrade` argument.

`pip install --upgrade git+https://github.com/earthlab/matplotcheck.git`

Then import it into python.

`import matplotcheck as mpc`

## Background

This library was developed to simplify the autograding process of Matplotlib plots.
Visually similar plots can be created in a variety of ways and hold different metadata.
Our goal is to abstract away these differences by creating a simple way to test student plots.

Beyond that, we have noticed common groupings of assertions for specific plot types.
`PlotBasicSuite`objects have been created to avoid repetition in writing out assertions,
and return a TestSuite instead. To run the suite after it has been created, use a unittest text runner.

## Examples

2D plot with x-axis label containing "x" and y-axis label containing "y" and "data"

```python
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

```python
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"

```python
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

```python
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
- Kristen Curry

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.0.1.tar.gz (21.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: matplotcheck-0.0.1.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for matplotcheck-0.0.1.tar.gz
Algorithm Hash digest
SHA256 63c2e113318724d04dbb3fd46596461a38cb1049c0504bb12f77c77ec49cc62b
MD5 f4f9a7f6490fd458b2518cdcd727c45c
BLAKE2b-256 0cfef05979ceb304153de1dfe9ffa7e627277e46a1d5b9508af59915f9224286

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