Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
8344d56
Merge pull request #1 from earthlab/master
nkorinek Feb 6, 2020
b87394d
Merge pull request #2 from earthlab/master
nkorinek Feb 12, 2020
7cf2703
Merge pull request #3 from earthlab/master
nkorinek Feb 12, 2020
c4d904e
Merge pull request #4 from earthlab/master
nkorinek Feb 13, 2020
c6deb54
Merge pull request #5 from earthlab/master
nkorinek Feb 13, 2020
30b4aa1
Merge pull request #7 from earthlab/master
nkorinek Feb 17, 2020
6ab2486
Merge pull request #8 from earthlab/master
nkorinek Mar 3, 2020
5077e25
Merge pull request #9 from earthlab/master
nkorinek Mar 7, 2020
4ff1b26
Merge pull request #10 from earthlab/master
nkorinek Mar 11, 2020
de25545
Merge pull request #11 from earthlab/master
nkorinek Mar 19, 2020
2f2f01d
Merge pull request #12 from earthlab/master
nkorinek Mar 19, 2020
031a710
Merge pull request #13 from earthlab/master
nkorinek Mar 20, 2020
7bb3216
Merge pull request #14 from earthlab/master
nkorinek Mar 23, 2020
f967e8a
Vignette for Testing Lines
nkorinek Mar 23, 2020
663fedc
codacy
nkorinek Mar 23, 2020
cd169d3
Merge pull request #15 from earthlab/master
nkorinek Mar 24, 2020
e0e3c34
Merge pull request #16 from earthlab/master
nkorinek Mar 30, 2020
8025984
Added in seaborn to dev-requirements
nkorinek Apr 2, 2020
11c57f9
Added in seaborn to dev-requirements right v
nkorinek Apr 2, 2020
7f6d8a7
Triggering rebuild
nkorinek Apr 2, 2020
208378c
Merge branch 'master' into lines-vignette
nkorinek Apr 2, 2020
60e57e4
Merge pull request #17 from earthlab/master
nkorinek Apr 6, 2020
f9b64dd
Adding changes discussed on github
nkorinek Apr 10, 2020
2050f4b
Fixed bug with how line limits are checke
nkorinek Apr 13, 2020
672bca7
Merge branch 'master' into lines-vignette
nkorinek Apr 20, 2020
5569d18
Merge pull request #18 from earthlab/master
nkorinek Apr 20, 2020
90b8128
Update setuptools from 42.0.2 to 45.2.0 (#190)
pyup-bot Feb 11, 2020
c96321c
raster inherits from vector rather than base (#76)
Feb 12, 2020
8e26cba
Allow geodataframes in assert_polygons (#188)
nkorinek Feb 13, 2020
49c4c24
fixing a few syntax errors (#194)
Feb 13, 2020
da32ef9
update changelog for release
Feb 14, 2020
f842822
Bump version: 0.1.1 → 0.1.2
Feb 14, 2020
eee471f
Add flake8 fix [WIP] (#199)
nkorinek Mar 2, 2020
77e8f76
Assert string accept spaces (#205)
nkorinek Mar 6, 2020
99e961a
Update codecov to 2.0.16 (#202)
pyup-bot Mar 7, 2020
3c37b7d
Contributors update (#213)
nkorinek Mar 10, 2020
d2dfa5a
Update setuptools from 45.2.0 to 46.0.0 (#215)
pyup-bot Mar 10, 2020
6b142e8
Add Assert points function & cleanup duplicate methods (#203)
nkorinek Mar 19, 2020
7ea9490
Update pytest from 5.3.5 to 5.4.1
pyup-bot Mar 13, 2020
a782271
merge
nkorinek Apr 20, 2020
e7b4652
Additional vector tests (#212)
nkorinek Mar 23, 2020
0f2fc16
Add tests to the Autograde module (#224)
nkorinek Mar 24, 2020
27251c3
Hist bin midpoints (#204)
nkorinek Mar 26, 2020
f3c384f
Update setuptools from 46.1.1 to 46.1.3 (#231)
pyup-bot Mar 26, 2020
654b3d1
Title assert accepts strings (#229)
nkorinek Apr 2, 2020
34e20da
M2r remove (#247)
nkorinek Apr 20, 2020
eb4c2d8
merge
nkorinek Apr 20, 2020
3f07d9b
# This is a combination of 2 commits.
pyup-bot Feb 11, 2020
beae1b5
Updating in order to squash commits!
nkorinek Apr 20, 2020
8e01ef5
Merging master
nkorinek Apr 20, 2020
bfc3321
merge
nkorinek Apr 20, 2020
31292f7
merging master
nkorinek Apr 20, 2020
79857b6
merging master
nkorinek Apr 20, 2020
44f0c3c
Merge branch 'master' into regression-asssert
Apr 23, 2020
66b8206
fix copyright on docs (#244)
Apr 21, 2020
63fa4e0
Add pillow (#254)
Apr 23, 2020
d8e08c4
Merge branch 'master' into regression-asssert
Apr 27, 2020
d8b99e3
Fixed issue with new way of checking that the data is covered by the …
nkorinek Apr 27, 2020
5873fb6
Changelog update
nkorinek Apr 27, 2020
5756fa6
merge
nkorinek Apr 27, 2020
3347ea0
merge
nkorinek Apr 27, 2020
f52150a
Merge
nkorinek Apr 27, 2020
5f0fd98
Merge branch 'earthlab-master'
nkorinek Apr 27, 2020
570dafb
Added changes suggest on github
nkorinek Apr 28, 2020
3c90acd
small fixes!
nkorinek Apr 28, 2020
5f68539
Added seaborn to the dev requirements
nkorinek Apr 30, 2020
978ab54
Slight change to dev requirements
nkorinek Apr 30, 2020
d6f70c4
Getting a valid version number
nkorinek Apr 30, 2020
ef9dfc9
Small modification to the title
nkorinek Apr 30, 2020
4dd7056
Small style update to remove 'we' from the vignette
nkorinek Apr 30, 2020
218752d
Update examples/plot_line_testing.py
May 1, 2020
e036b9d
minor edits
May 1, 2020
efab5a2
Changelog to rst (#267)
nkorinek May 1, 2020
a7dfdc7
setup greetings! (#257)
May 1, 2020
1a44f38
merge
nkorinek May 1, 2020
74c770a
Added some of the changes requested on github
nkorinek May 1, 2020
f9e374a
fixing merge conflicts
nkorinek May 1, 2020
e0e5d0a
Merge branch 'master' into lines-vignette
nkorinek May 1, 2020
7b887bd
merge
nkorinek May 7, 2020
1a2252a
Merge branch 'earthlab-master'
nkorinek May 7, 2020
75e2fdd
small edits
May 13, 2020
43cdccd
title update
May 13, 2020
d3c1ba6
Add template for PR
May 12, 2020
a850b76
Timeseries tests (#273)
nkorinek May 13, 2020
43bc9cb
Update pytest from 5.4.1 to 5.4.2 (#275)
pyup-bot May 14, 2020
f81f819
remove rebase
May 14, 2020
57646ec
Test coverage for lines (#274)
nkorinek May 14, 2020
dda862b
merge
nkorinek May 14, 2020
824684f
Draft of section add
nkorinek May 14, 2020
9f26868
Changes from upstream
nkorinek May 14, 2020
577a59c
Added changes requested in github, made a small fix to
nkorinek May 14, 2020
475b19c
Merge branch 'master' into lines-vignette
nkorinek May 14, 2020
85f9afe
small merge error
nkorinek May 14, 2020
3226ba8
took out plt.show()
nkorinek May 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en/1.0.0/>`
Unreleased
----------

- Add a vignette for testing vector data plots. (@nkorinek, #208)
- Changed how `assert_lines` checks the limits of lines (@nkorinek, #243)
- Changed changelog to an rst file. (@nkorinek, #266)
- Add a vignette for testing vector data plots. (@nkorinek, #208)
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pip==19.0.3
descartes==1.1.0
seaborn>=0.9.1
pillow==7.1.2
seaborn>=0.9.1
165 changes: 165 additions & 0 deletions examples/plot_line_testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
"""
Test Regression and 1:1 Lines On Plots Using Matplotcheck
===========================================================

You can use MatPlotcheck to test lines on plots. In this example you will
learn how to test that a 1:1 line or a regression line is correct as
rendered on a scatter plot.
"""

################################################################################
# To begin, import the required Python packages.

import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy import stats
import pandas as pd
import matplotcheck.base as pt
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not an ideal import convention pt.

Nathan - let's look into being able to import ANY of the mpc tester objects using
mpc.RasterTester, mpc.VectorTester, mpc.PlotTester

i think we can do this by modifying the init file or similar to what they do in geopandas??


################################################################################
# Create Example Data
# -------------------
# Below you create some data to add to a scatter plot. You will use the
# points to calculate and create a linear regression fit line to your
# plot. You will also add a 1:1 line to your plot. This will allow you to
# compare the slope of the regression output to a standard 1:1 fit.

# Create Pandas DataFrame containing data points
col1 = np.random.randint(25, size=15)
col2 = np.random.randint(25, size=15)
data = pd.DataFrame({'data1':col1, 'data2':col2})

# Plot data points, regression line, and one-to-one (1:1) line for reference
fig, ax = plt.subplots()

# Use Seaborn to calculate and plot a regression line + associated points
sns.regplot('data1', 'data2',
data=data,
color='purple',
ax=ax,
scatter=True)

# Add 1:1 line to your plot
ax.plot((0, 1), (0, 1), transform=ax.transAxes, ls='--', c='k')

ax.set(xlabel='data1',
ylabel='data2',
title='Example Data Regression Plot',
xlim=(0, 25),
ylim=(0, 25));

################################################################################
# Test Line Plots Using a matplotcheck.PlotTester Object
# ------------------------------------------------------------
# Once you have your plot, you can test the lines on the plot using
# MatPlotCheck. To begin, create a ``matplotcheck.PlotTester``
# object. MatPlotCheck can test to see if there is a 1:1 and / or a regression
# line on your plot. It will also test that the line has the correct
# y-intercept and slope.

# Convert matplotlib plot axes object into a matplotcheck PlotTester object
line_plot_tester = pt.PlotTester(ax)

################################################################################
# Test For Regression and 1:1 Lines on a Plot
# --------------------------------------------
# You can use the method ``assert_lines_of_type()`` to test if a 1:1 or
# linear regression line (or both line types) are present in the plot.

# Check regression line is accurate to the points in the plot
line_plot_tester.assert_lines_of_type(line_types=['linear-regression'])

# Check onetoone line is present in the data. Set check_coverage to false since
# the onetoone line goes past the extent of the points.
line_plot_tester.assert_lines_of_type(
line_types=['onetoone'], check_coverage=False
)

################################################################################
# Test Slope and Y Intercept
# --------------------------
# You can also test the slope and y-intercept of a line to ensure
# that the line is correct. If you made
# your line from a list of vertices, you can use the
# ``line_figure_tests.get_slope_yintercept()`` method of the PlotTester object,
# to get the slope and y-intercept. However, if you made your line
# from a regression function, it will take an extra step to get the slope and
# intercept data. In this example, ``stats.linregress`` is used to calculate
# the slope and intercept data. Once you have created that data, you can plug
# it into the ``assert_line()`` function to ensure your line in your plot has
# the correct values.

# Get slope and y intercept data of regression line for testing
slope_data, intercept_data, _, _, _ = stats.linregress(
data.data1, data.data2
)

# Check that slope and y intercept are correct (expected) values
line_plot_tester.assert_line(slope_exp=slope_data, intercept_exp=intercept_data)


################################################################################
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look at this when we fix the other imports in a locally build but i'm wondering if this should be a NOTE rather then a section at the bottom of the page. just so it stands out. what do you think @nkorinek ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lwasser this could definitely be a note

# Test Other Aspects of the Plot
# ------------------------------
# Plots with linear regression lines and one to one lines generally have other
# important aspects to the plots aside from the lines themselves, such as the
# points the regression is based off of, or the labels of the plot. You can
# test those aspects as well to ensure they are accurate.

# Checking key words are found in the title
line_plot_tester.assert_title_contains(
strings_expected=[["Example"], ["Regression"], ["Plot"]]
)

# Check labels contain key words
line_plot_tester.assert_axis_label_contains(
axis="x", strings_expected=["data1"]
)
line_plot_tester.assert_axis_label_contains(
axis="y", strings_expected=["data2"]
)

# Checking point data matches the expected data
line_plot_tester.assert_xydata(
xy_expected=data, xcol=['data1'], ycol=['data2'], points_only=True
)

################################################################################
#
# .. note::
# Matplotcheck can be used to test plots in Jupyter Notebooks as well. The
# main difference is how you access the axes objects from the plot that you
# want to test. Below is an example of how you could access the axes of a
# plot you want to test in a Jupyter Notebook.

# First, import the Notebook module from Matplotcheck
import matplotcheck.notebook as nb

# Plot the data
fig, ax = plt.subplots()

# Points and regression line
sns.regplot('data1', 'data2',
data=data,
color='purple',
ax=ax)

# 1:1 line
ax.plot((0, 1), (0, 1), transform=ax.transAxes, ls='--', c='k')

ax.set(xlabel='data1',
ylabel='data2',
title='Example Data Regression Plot',
xlim=(0, 25),
ylim=(0, 25));

# Here is where you access the axes objects of the plot for testing.
# You can add the code line below to the end of any plot cell to store all axes
# objects created by matplotlib in that cell.
axis_object = nb.convert_axes(plt, which_axes="current")

# This object can then be turned into a PlotTester object.
line_plot_tester_2 = pt.PlotTester(axis_object)

# Now you can run the tests as you did earlier!
8 changes: 4 additions & 4 deletions matplotcheck/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,8 @@ def assert_xydata(
the assertion being run."""
try:
np.testing.assert_array_max_ulp(
xy_data["x"].to_numpy(dtype=np.float64),
xy_expected[xcol].to_numpy(dtype=np.float64),
xy_data["x"].to_numpy(dtype=np.float64).flatten(),
xy_expected[xcol].to_numpy(dtype=np.float64).flatten(),
5,
)
except AssertionError:
Expand All @@ -944,8 +944,8 @@ def assert_xydata(
)
try:
np.testing.assert_array_max_ulp(
xy_data["y"].to_numpy(dtype=np.float64),
xy_expected[ycol].to_numpy(dtype=np.float64),
xy_data["y"].to_numpy(dtype=np.float64).flatten(),
xy_expected[ycol].to_numpy(dtype=np.float64).flatten(),
5,
)

Expand Down