From c1bb42b0993caf83044e425ea481fbb2c1f40b57 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 26 Feb 2020 15:38:29 -0700 Subject: [PATCH 01/41] Added a get_points() and assert_points() function to the vector tester. --- matplotcheck/vector.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 10610602..c52e4676 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -237,6 +237,27 @@ def assert_collection_sorted_by_markersize(self, df_expected, sort_column): err_msg="Markersize not based on {0} values".format(sort_column), ) + def get_points(self): + """yeet""" + points = self.get_xy(points_only=True).sort_values(by="x") + points.reset_index(inplace=True, drop=True) + return points + + def assert_points(self, points_expected, m="Incorrect Line Data"): + """yote""" + if isinstance(points_expected, gpd.geodataframe.GeoDataFrame): + xy_expected = pd.DataFrame(columns=['x', 'y']) + xy_expected['x'] = points_expected.geometry.x + xy_expected['y'] = points_expected.geometry.y + xy_expected = xy_expected.sort_values(by="x") + xy_expected.reset_index(inplace=True, drop=True) + pd.testing.assert_frame_equal(left=self.get_points(), right=xy_expected) + else: + raise ValueError( + "points_expected is not expected type: GeoDataFrame" + ) + + ### LINES ### def _convert_multilines(self, df, column_title): From 6cd48e3c867e88e445878e941f1844800862ad0a Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 26 Feb 2020 16:43:03 -0700 Subject: [PATCH 02/41] Added in get_points() and assert_points() functions with tests --- matplotcheck/tests/test_vector.py | 56 +++++++++++++++++++++++++++++++ matplotcheck/vector.py | 9 +++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/matplotcheck/tests/test_vector.py b/matplotcheck/tests/test_vector.py index e65a0611..6c3b06f5 100644 --- a/matplotcheck/tests/test_vector.py +++ b/matplotcheck/tests/test_vector.py @@ -20,6 +20,28 @@ def poly_geo_plot(basic_polygon_gdf): return VectorTester(axis) +@pytest.fixture +def point_geo_plot(pd_gdf): + """Create a point plot for testing""" + fig, ax = plt.subplots() + + pd_gdf.plot(ax=ax) + ax.set_title("My Plot Title", fontsize=30) + ax.set_xlabel("x label") + ax.set_ylabel("y label") + + axis = plt.gca() + + return VectorTester(axis) + + +@pytest.fixture +def bad_pd_gdf(pd_gdf): + """Create a point geodataframe with slightly wrong values for testing""" + return gpd.GeoDataFrame(geometry=gpd.points_from_xy( + pd_gdf.geometry.x + 1, pd_gdf.geometry.y + 1) + ) + def test_list_of_polygons_check(poly_geo_plot, basic_polygon): """Check that the polygon assert works with a list of polygons.""" x, y = basic_polygon.exterior.coords.xy @@ -85,3 +107,37 @@ def test_polygon_custom_fail_message(poly_geo_plot, basic_polygon): poly_list = [(x[0] + 0.5, x[1]) for x in list(zip(x, y))] poly_geo_plot.assert_polygons(poly_list, m="Test Message") plt.close() + + +def test_point_geometry_pass(point_geo_plot, pd_gdf): + """Check that the point geometry test recognizes correct points.""" + point_geo_plot.assert_points(points_expected=pd_gdf) + + +def test_point_geometry_fail(point_geo_plot, bad_pd_gdf): + """Check that the point geometry test recognizes incorrect points.""" + with pytest.raises(AssertionError, match="Incorrect Point Data"): + point_geo_plot.assert_points(points_expected=bad_pd_gdf) + + +def test_assert_point_fails_list(point_geo_plot, pd_gdf): + """ + Check that the point geometry test fails anything that's not a + GeoDataFrame + """ + list_geo = [list(pd_gdf.geometry.x), list(pd_gdf.geometry.y)] + with pytest.raises(ValueError, match="points_expected is not expected"): + point_geo_plot.assert_points(points_expected=list_geo) + +def test_get_points(point_geo_plot, pd_gdf): + """Tests that get_points returns correct values""" + xy_values = point_geo_plot.get_points() + assert(list(sorted(xy_values.x)) == sorted(list(pd_gdf.geometry.x))) + assert(list(sorted(xy_values.y)) == sorted(list(pd_gdf.geometry.y))) + + +def test_assert_points_custom_message(point_geo_plot, bad_pd_gdf): + """Tests that a custom error message is passed.""" + message = "Test message" + with pytest.raises(AssertionError, match="Test message"): + point_geo_plot.assert_points(points_expected=bad_pd_gdf, m=message) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index c52e4676..1242e411 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -243,7 +243,7 @@ def get_points(self): points.reset_index(inplace=True, drop=True) return points - def assert_points(self, points_expected, m="Incorrect Line Data"): + def assert_points(self, points_expected, m="Incorrect Point Data"): """yote""" if isinstance(points_expected, gpd.geodataframe.GeoDataFrame): xy_expected = pd.DataFrame(columns=['x', 'y']) @@ -251,7 +251,12 @@ def assert_points(self, points_expected, m="Incorrect Line Data"): xy_expected['y'] = points_expected.geometry.y xy_expected = xy_expected.sort_values(by="x") xy_expected.reset_index(inplace=True, drop=True) - pd.testing.assert_frame_equal(left=self.get_points(), right=xy_expected) + try: + pd.testing.assert_frame_equal( + left=self.get_points(), right=xy_expected + ) + except AssertionError: + raise AssertionError(m) else: raise ValueError( "points_expected is not expected type: GeoDataFrame" From 5e6a175f29591515af47aeb4f0a025e6685ca1d4 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 26 Feb 2020 16:47:19 -0700 Subject: [PATCH 03/41] Added proper documentation --- matplotcheck/vector.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 1242e411..07384fd6 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -238,13 +238,30 @@ def assert_collection_sorted_by_markersize(self, df_expected, sort_column): ) def get_points(self): - """yeet""" + """Returns a Pandas dataframe with all x, y values for points on axis. + + Returns + ------- + output: DataFrame with columns 'x' and 'y'. Each row represents one + points coordinates. + """ points = self.get_xy(points_only=True).sort_values(by="x") points.reset_index(inplace=True, drop=True) return points def assert_points(self, points_expected, m="Incorrect Point Data"): - """yote""" + """ + Asserts the point data in Axes ax is equal to points_expected data + with error message m. + If points_expected not a GeoDataFrame, test fails. + + Parameters + ---------- + points_expected : GeoDataFrame + GeoDataFrame with the expected points for the axis. + m : string (default = "Incorrect Point Data") + String error message if assertion is not met. + """ if isinstance(points_expected, gpd.geodataframe.GeoDataFrame): xy_expected = pd.DataFrame(columns=['x', 'y']) xy_expected['x'] = points_expected.geometry.x From 408ab38682a71c979e5defed7a3f4bb74528719b Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 26 Feb 2020 16:54:45 -0700 Subject: [PATCH 04/41] Small fix to please codacy --- matplotcheck/tests/test_vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matplotcheck/tests/test_vector.py b/matplotcheck/tests/test_vector.py index 6c3b06f5..99ac3a95 100644 --- a/matplotcheck/tests/test_vector.py +++ b/matplotcheck/tests/test_vector.py @@ -23,7 +23,7 @@ def poly_geo_plot(basic_polygon_gdf): @pytest.fixture def point_geo_plot(pd_gdf): """Create a point plot for testing""" - fig, ax = plt.subplots() + _, ax = plt.subplots() pd_gdf.plot(ax=ax) ax.set_title("My Plot Title", fontsize=30) From 8325ed9c0bee00f44808baba7bc17cd5e9368f99 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 26 Feb 2020 17:06:20 -0700 Subject: [PATCH 05/41] black --- matplotcheck/tests/test_vector.py | 14 +++++++++----- matplotcheck/vector.py | 7 +++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/matplotcheck/tests/test_vector.py b/matplotcheck/tests/test_vector.py index 99ac3a95..952df150 100644 --- a/matplotcheck/tests/test_vector.py +++ b/matplotcheck/tests/test_vector.py @@ -38,9 +38,12 @@ def point_geo_plot(pd_gdf): @pytest.fixture def bad_pd_gdf(pd_gdf): """Create a point geodataframe with slightly wrong values for testing""" - return gpd.GeoDataFrame(geometry=gpd.points_from_xy( - pd_gdf.geometry.x + 1, pd_gdf.geometry.y + 1) - ) + return gpd.GeoDataFrame( + geometry=gpd.points_from_xy( + pd_gdf.geometry.x + 1, pd_gdf.geometry.y + 1 + ) + ) + def test_list_of_polygons_check(poly_geo_plot, basic_polygon): """Check that the polygon assert works with a list of polygons.""" @@ -129,11 +132,12 @@ def test_assert_point_fails_list(point_geo_plot, pd_gdf): with pytest.raises(ValueError, match="points_expected is not expected"): point_geo_plot.assert_points(points_expected=list_geo) + def test_get_points(point_geo_plot, pd_gdf): """Tests that get_points returns correct values""" xy_values = point_geo_plot.get_points() - assert(list(sorted(xy_values.x)) == sorted(list(pd_gdf.geometry.x))) - assert(list(sorted(xy_values.y)) == sorted(list(pd_gdf.geometry.y))) + assert list(sorted(xy_values.x)) == sorted(list(pd_gdf.geometry.x)) + assert list(sorted(xy_values.y)) == sorted(list(pd_gdf.geometry.y)) def test_assert_points_custom_message(point_geo_plot, bad_pd_gdf): diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 07384fd6..988cc677 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -263,9 +263,9 @@ def assert_points(self, points_expected, m="Incorrect Point Data"): String error message if assertion is not met. """ if isinstance(points_expected, gpd.geodataframe.GeoDataFrame): - xy_expected = pd.DataFrame(columns=['x', 'y']) - xy_expected['x'] = points_expected.geometry.x - xy_expected['y'] = points_expected.geometry.y + xy_expected = pd.DataFrame(columns=["x", "y"]) + xy_expected["x"] = points_expected.geometry.x + xy_expected["y"] = points_expected.geometry.y xy_expected = xy_expected.sort_values(by="x") xy_expected.reset_index(inplace=True, drop=True) try: @@ -279,7 +279,6 @@ def assert_points(self, points_expected, m="Incorrect Point Data"): "points_expected is not expected type: GeoDataFrame" ) - ### LINES ### def _convert_multilines(self, df, column_title): From 7ac5d41ac3131913dd7d3dbb8c5fd2e6f571bcc1 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Thu, 27 Feb 2020 10:38:39 -0700 Subject: [PATCH 06/41] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index de1bc962..aac3da87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +* Created functions to test point geometries in VectorTester (@nkorinek, #176) ## [0.1.2] * Created a vignette covering the testing of histograms (@ryla5068, #149) From c75e42152e3ec06d0f8c4feadfca6703edba505d Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 16 Mar 2020 15:41:13 -0600 Subject: [PATCH 07/41] Rough draft for bug fix --- matplotcheck/vector.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 45018a68..e6c8e7c4 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -270,11 +270,23 @@ def assert_points(self, points_expected, m="Incorrect Point Data"): String error message if assertion is not met. """ if isinstance(points_expected, gpd.geodataframe.GeoDataFrame): + points = self.get_points() xy_expected = pd.DataFrame(columns=["x", "y"]) xy_expected["x"] = points_expected.geometry.x xy_expected["y"] = points_expected.geometry.y xy_expected = xy_expected.sort_values(by="x") xy_expected.reset_index(inplace=True, drop=True) + if len(points) != len(xy_expected): + points_zeros = (points['x'] == 0) & (points['y'] == 0) + if points_zeros.any(): + expected_zeros = (xy_expected['x'] == 0) & (xy_expected['y'] == 0) + keep = expected_zeros.sum() + zeros_index_vals = points_zeros.index[points_zeros.tolist()] + for i in range(keep): + points_zeros.at[zeros_index_vals[i]] = False + points = points[~points_zeros].reset_index(inplace=True, drop=True) + else: + raise AssertionError("points_expected's length does not match the stored data's length.") try: pd.testing.assert_frame_equal( left=self.get_points(), right=xy_expected From 075052cb53f62b2a63e5addf17ed2c4fda2c32a6 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 16 Mar 2020 15:57:34 -0600 Subject: [PATCH 08/41] Fixed bug with multiple geometries plotted alongside bug with identical x values causing failure! --- matplotcheck/vector.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index e6c8e7c4..4b694f2e 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -252,7 +252,7 @@ def get_points(self): output: DataFrame with columns 'x' and 'y'. Each row represents one points coordinates. """ - points = self.get_xy(points_only=True).sort_values(by="x") + points = self.get_xy(points_only=True).sort_values(by=["x", "y"]) points.reset_index(inplace=True, drop=True) return points @@ -274,23 +274,28 @@ def assert_points(self, points_expected, m="Incorrect Point Data"): xy_expected = pd.DataFrame(columns=["x", "y"]) xy_expected["x"] = points_expected.geometry.x xy_expected["y"] = points_expected.geometry.y - xy_expected = xy_expected.sort_values(by="x") + xy_expected = xy_expected.sort_values(by=["x", "y"]) xy_expected.reset_index(inplace=True, drop=True) if len(points) != len(xy_expected): - points_zeros = (points['x'] == 0) & (points['y'] == 0) + points_zeros = (points["x"] == 0) & (points["y"] == 0) if points_zeros.any(): - expected_zeros = (xy_expected['x'] == 0) & (xy_expected['y'] == 0) + expected_zeros = (xy_expected["x"] == 0) & ( + xy_expected["y"] == 0 + ) keep = expected_zeros.sum() - zeros_index_vals = points_zeros.index[points_zeros.tolist()] + zeros_index_vals = points_zeros.index[ + points_zeros.tolist() + ] for i in range(keep): - points_zeros.at[zeros_index_vals[i]] = False - points = points[~points_zeros].reset_index(inplace=True, drop=True) + points_zeros.at[zeros_index_vals[i]] = False + points = points[~points_zeros].reset_index(drop=True) else: - raise AssertionError("points_expected's length does not match the stored data's length.") + raise AssertionError( + "points_expected's length does not match the stored" + "data's length." + ) try: - pd.testing.assert_frame_equal( - left=self.get_points(), right=xy_expected - ) + pd.testing.assert_frame_equal(left=points, right=xy_expected) except AssertionError: raise AssertionError(m) else: From a7927259eaf243458a2e6701f538f3647ae1c4b4 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 16 Mar 2020 16:00:03 -0600 Subject: [PATCH 09/41] typo --- matplotcheck/vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 4b694f2e..a2894079 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -216,7 +216,7 @@ def sort_collection_by_markersize(self): return df def assert_collection_sorted_by_markersize(self, df_expected, sort_column): - """Asserts a collection of points vary in size by column expresse din + """Asserts a collection of points vary in size by column expressed in sort_column Parameters From 540f328f0c0198c290470b5a910ad703059903c4 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 16 Mar 2020 16:53:12 -0600 Subject: [PATCH 10/41] Created vignette for testing vector object --- examples/plot_vector_testing.py | 172 ++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 examples/plot_vector_testing.py diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py new file mode 100644 index 00000000..40fff2c5 --- /dev/null +++ b/examples/plot_vector_testing.py @@ -0,0 +1,172 @@ +""" +Testing Vectors with MatPlotCheck +================================= + +These are some examples of using the basic functionality of MatPlotCheck +to test vector plots in Python. + +""" + +################################################################################ +# Setup +# ----- +# You will start by importing the required packages and geometry objects +# to plot and test. + +import matplotlib.pyplot as plt +import geopandas as gpd +import pandas as pd +from matplotcheck.vector import VectorTester +import matplotcheck.notebook as nb +from shapely.geometry import Polygon, LineString +import numpy as np + +# Create geometry objects + +# Polygon GDF +coords = [(2, 4), (2, 4.25), (4.25, 4.25), (4.25, 2), (2, 2)] +coords_b = [(i[0]+5, i[1]+7) for i in coords] +polygon_a = Polygon(coords) +polygon_b = Polygon(coords_b) +polygon_gdf = gpd.GeoDataFrame( + [1, 2], geometry=[polygon_a, polygon_b], crs="epsg:4326") + + +# Line GDF +linea = LineString([(1, 1), (2, 2), (3, 2), (5, 3)]) +lineb = LineString([(3, 4), (5, 7), (12, 2), (10, 5), (9, 7.5)]) +line_gdf = gpd.GeoDataFrame([1, 2], geometry=[linea, lineb], crs="epsg:4326") + +# MultiLine GDF + +linec = LineString([(2, 1), (3, 1), (4, 1), (5, 2)]) +multi_line_gdf = gpd.GeoDataFrame(geometry=gpd.GeoSeries( + [line_gdf.unary_union, linec]), crs="epsg:4326") +multi_line_gdf["attr"] = ["road", "stream"] + +# Point GDF + +points = pd.DataFrame( + { + "lat": np.array([1, 2, 1, 0, 4]), + "lon": np.array([3, 4, 0, 0, 1]), + } +) + +point_gdf = gpd.GeoDataFrame( + {"A": np.arange(5), "B": np.arange(5)}, geometry=gpd.points_from_xy(points.lon, points.lat), crs="epsg:4326" +) +point_gdf["attr2"] = ["Tree", "Tree", "Bush", "Bush", "Bush"] + +# Symbology for the legend + +line_symb = {"road": "black", "stream": "blue"} +point_symb = {"Tree": "green", "Bush": "brown"} + +################################################################################ +# Plotting the Geometry Objects and Storing the VectorTester Object +# ----------------------------------------------------------------- +# Now you can plot the geometry objects you've made. In order to plot them with +# a legend, you will have to loop through the geometry objects that have +# attributes and plot by attribute for each case. +# +# Once you've created the Matplotlib plot, you can collect the data! You +# can store the axes with the MatPlotCheck notebook function convert_axes, +# which will allow you to create the VectorTester object in a later cell. + +# Collecting Vector Tester objects + +fig, ax = plt.subplots() + +# Plotting polygon geodataframe + +polygon_gdf.plot(ax=ax, color="purple") + +# Plotting line geodataframe + +for ctype, lines in multi_line_gdf.groupby('attr'): + color = line_symb[ctype] + label = ctype + lines.plot(color=color, ax=ax, label=label) + +# Plotting point geodataframe + +for ctype, points in point_gdf.groupby('attr2'): + color = point_symb[ctype] + label = ctype + points.plot(color=color, ax=ax, label=label) + +# Adding legend + +ax.legend(title="Legend", loc=(1.1, .1)) + +vector_test_plot_hold = nb.convert_axes(plt, which_axes="current") + +################################################################################ +# Creating the VectorTester Object +# -------------------------------- +# Once you've stored the axes, you'll need to create the VectorTester object +# itself using the stored axes. + +vector_test = VectorTester(vector_test_plot_hold) + +############################################################################### +# +# .. note:: +# Each geometry type must be tested seperately in VectorTester. So, if your +# plot has multiple geometry types, such as lines, polygons, and points, +# make sure to check each geometry type seperately! + +################################################################################ +# Testing Legend Attributes +# ------------------------- +# In addition to the legend tests available in the base module for MatPlotCheck, +# there are additional tests you can run to check vector legends, as shown +# below. + +# Check legends in doesn't overlay the plot + +vector_test.assert_legend_no_overlay_content() + +# If there are multiple legends, check they don't overlap. + +vector_test.assert_no_legend_overlap() + +################################################################################ +# Testing Point Values and Geometry +# --------------------------------- +# You can check that both the position of the points and there plot values are +# accurate with the tests below. + +# Check points geometry + +vector_test.assert_points(point_gdf) + +# Check points plotted by type + +vector_test.assert_points_grouped_by_type(point_gdf, "attr2") + +################################################################################ +# Testing Line Values and Geometry +# -------------------------------- +# Similarly to points, you can check the position and plot values of line +# geometries are accurate with the tests below. + +# Check lines geometry + +vector_test.assert_lines(multi_line_gdf) + +# Check lines plotted by type + +vector_test.assert_lines_grouped_by_type(multi_line_gdf, "attr") + +################################################################################ +# Testing Polygon Geometry +# ------------------------ +# Currently, MatPlotCheck is unable to check that polygons were plotted by type. +# Eventually this will be supported. For the time being though, you can still +# check that polygons are plotted correctly! + +# Check Polygons + +vector_test.assert_polygons(polygon_gdf) From 6876a504d6c9c3d09ba4b861da600d9a80d71382 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Tue, 17 Mar 2020 13:02:31 -0600 Subject: [PATCH 11/41] Fixed small bug with markersize --- matplotcheck/vector.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index a2894079..038a4b4d 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -196,22 +196,23 @@ def sort_collection_by_markersize(self): """ df = pd.DataFrame(columns=("x", "y", "markersize")) for c in self.ax.collections: - offsets, markersizes = c.get_offsets(), c.get_sizes() - x_data, y_data = ( - [offset[0] for offset in offsets], - [offset[1] for offset in offsets], - ) - if len(markersizes) == 1: - markersize = [markersizes[0]] * len(offsets) - df2 = pd.DataFrame( - {"x": x_data, "y": y_data, "markersize": markersize} - ) - df = df.append(df2) - elif len(markersizes) == len(offsets): - df2 = pd.DataFrame( - {"x": x_data, "y": y_data, "markersize": markersizes} + if isinstance(c, matplotlib.collections.PathCollection): + offsets, markersizes = c.get_offsets(), c.get_sizes() + x_data, y_data = ( + [offset[0] for offset in offsets], + [offset[1] for offset in offsets], ) - df = df.append(df2) + if len(markersizes) == 1: + markersize = [markersizes[0]] * len(offsets) + df2 = pd.DataFrame( + {"x": x_data, "y": y_data, "markersize": markersize} + ) + df = df.append(df2) + elif len(markersizes) == len(offsets): + df2 = pd.DataFrame( + {"x": x_data, "y": y_data, "markersize": markersizes} + ) + df = df.append(df2) df = df.sort_values(by="markersize").reset_index(drop=True) return df From 3ddf05beac81fe4bfe52e6fbc6d38e517dda0609 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Tue, 17 Mar 2020 13:12:48 -0600 Subject: [PATCH 12/41] Added fixed test for marker size --- examples/plot_vector_testing.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 40fff2c5..c8e59297 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -91,10 +91,13 @@ # Plotting point geodataframe +size = 0 + for ctype, points in point_gdf.groupby('attr2'): color = point_symb[ctype] label = ctype - points.plot(color=color, ax=ax, label=label) + size += 100 + points.plot(color=color, ax=ax, label=label, markersize=size) # Adding legend @@ -136,7 +139,8 @@ # Testing Point Values and Geometry # --------------------------------- # You can check that both the position of the points and there plot values are -# accurate with the tests below. +# accurate with the tests below. For points, you can also check that the +# size of each point varies based on it's attributes. # Check points geometry @@ -146,6 +150,10 @@ vector_test.assert_points_grouped_by_type(point_gdf, "attr2") +# Check points size varies based on a variable. + +vector_test.assert_collection_sorted_by_markersize(point_gdf, "attr2") + ################################################################################ # Testing Line Values and Geometry # -------------------------------- From 62b6b2d07eddb6dcfb4d8f0b95c6c002255210a8 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Tue, 17 Mar 2020 13:17:37 -0600 Subject: [PATCH 13/41] Added small note --- examples/plot_vector_testing.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index c8e59297..4288933e 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -127,6 +127,13 @@ # there are additional tests you can run to check vector legends, as shown # below. +############################################################################### +# +# .. note:: +# For these tests, you can know they passed if they don't raise an +# AssertionError. If they were to fail, they would throw an error stating +# what went wrong. + # Check legends in doesn't overlay the plot vector_test.assert_legend_no_overlay_content() From b73e4ef761fd41d52d5b650f367ec780464c5177 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Tue, 17 Mar 2020 13:20:25 -0600 Subject: [PATCH 14/41] Added comments explaining code --- matplotcheck/vector.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 038a4b4d..c7410820 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -277,7 +277,10 @@ def assert_points(self, points_expected, m="Incorrect Point Data"): xy_expected["y"] = points_expected.geometry.y xy_expected = xy_expected.sort_values(by=["x", "y"]) xy_expected.reset_index(inplace=True, drop=True) + # Fix for failure if more than points were plotted in matplotlib if len(points) != len(xy_expected): + # Checks if there are extra 0, 0 coords in the DataFrame + # returned from self.get_points and removes them. points_zeros = (points["x"] == 0) & (points["y"] == 0) if points_zeros.any(): expected_zeros = (xy_expected["x"] == 0) & ( From ec63ba175359b3bf4e8a740a3879f8c989e47fa5 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Tue, 17 Mar 2020 14:31:44 -0600 Subject: [PATCH 15/41] Getting rid of trailing whitespace --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 4288933e..7d374318 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -132,7 +132,7 @@ # .. note:: # For these tests, you can know they passed if they don't raise an # AssertionError. If they were to fail, they would throw an error stating -# what went wrong. +# what went wrong. # Check legends in doesn't overlay the plot From d2a1972736d60a9feb2c279fac762731f41e1abd Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 18 Mar 2020 10:15:01 -0600 Subject: [PATCH 16/41] Taking out redundant tests --- matplotcheck/vector.py | 57 ------------------------------------------ 1 file changed, 57 deletions(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index c7410820..655a1e6c 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -21,63 +21,6 @@ def __init__(self, ax): """Initialize the vector tester""" super(VectorTester, self).__init__(ax) - def assert_legend_no_overlay_content( - self, m="Legend overlays plot contents" - ): - """Asserts that each legend does not overlay plot contents with error - message m - - Parameters - --------- - m: string - error message if assertion is not met - """ - plot_extent = self.ax.get_window_extent().get_points() - legends = self.get_legends() - for leg in legends: - leg_extent = leg.get_window_extent().get_points() - legend_left = leg_extent[1][0] < plot_extent[0][0] - legend_right = leg_extent[0][0] > plot_extent[1][0] - legend_below = leg_extent[1][1] < plot_extent[0][1] - assert legend_left or legend_right or legend_below, m - - def _legends_overlap(self, b1, b2): - """Helper function for assert_no_legend_overlap - Boolean value if points of window extents for b1 and b2 overlap - - Parameters - ---------- - b1: bounding box of window extents - b2: bounding box of window extents - - Returns - ------ - boolean value that says if bounding boxes b1 and b2 overlap - """ - x_overlap = (b1[0][0] <= b2[1][0] and b1[0][0] >= b2[0][0]) or ( - b1[1][0] <= b2[1][0] and b1[1][0] >= b2[0][0] - ) - y_overlap = (b1[0][1] <= b2[1][1] and b1[0][1] >= b2[0][1]) or ( - b1[1][1] <= b2[1][1] and b1[1][1] >= b2[0][1] - ) - return x_overlap and y_overlap - - def assert_no_legend_overlap(self, m="Legends overlap eachother"): - """Asserts there are no two legends in Axes ax that overlap each other - with error message m - - Parameters - ---------- - m: string error message if assertion is not met - """ - legends = self.get_legends() - n = len(legends) - for i in range(n - 1): - leg_extent1 = legends[i].get_window_extent().get_points() - for j in range(i + 1, n): - leg_extent2 = legends[j].get_window_extent().get_points() - assert not self._legends_overlap(leg_extent1, leg_extent2), m - """ Check Data """ def _convert_length(self, arr, n): From 014118e19223d0e4ef43ea0406bdf6905942edc2 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 18 Mar 2020 10:19:45 -0600 Subject: [PATCH 17/41] Took out unnecessary examples --- examples/plot_vector_testing.py | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 7d374318..1b1d2aa9 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -120,13 +120,6 @@ # plot has multiple geometry types, such as lines, polygons, and points, # make sure to check each geometry type seperately! -################################################################################ -# Testing Legend Attributes -# ------------------------- -# In addition to the legend tests available in the base module for MatPlotCheck, -# there are additional tests you can run to check vector legends, as shown -# below. - ############################################################################### # # .. note:: @@ -134,14 +127,6 @@ # AssertionError. If they were to fail, they would throw an error stating # what went wrong. -# Check legends in doesn't overlay the plot - -vector_test.assert_legend_no_overlay_content() - -# If there are multiple legends, check they don't overlap. - -vector_test.assert_no_legend_overlap() - ################################################################################ # Testing Point Values and Geometry # --------------------------------- From 7e59d4779ab905a67dcce2a900f886616c3b62cd Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 18 Mar 2020 12:36:45 -0600 Subject: [PATCH 18/41] Typo --- matplotcheck/vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 655a1e6c..61f9c00c 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -103,7 +103,7 @@ def get_points_by_attributes(self): return sorted([sorted(p) for p in points_grouped]) def assert_points_grouped_by_type( - self, data_exp, sort_column, m="Point attribtues not accurate by type" + self, data_exp, sort_column, m="Point attributes not accurate by type" ): """Asserts that the points on Axes ax display attributes based on their type with error message m From 3b8a20b91cd72ab4faf72879ff0fe3ae0eedab91 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 18 Mar 2020 14:30:27 -0600 Subject: [PATCH 19/41] Fixing how vector checks for truth value of a dataframe --- matplotcheck/vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matplotcheck/vector.py b/matplotcheck/vector.py index 61f9c00c..ab77c8da 100644 --- a/matplotcheck/vector.py +++ b/matplotcheck/vector.py @@ -455,7 +455,7 @@ def assert_lines_grouped_by_type( grouped_exp = sorted([sorted(l) for l in grouped_exp]) plt.close(fig) np.testing.assert_equal(groups, grouped_exp, m) - elif not lines_expected: + elif lines_expected is None: pass else: raise ValueError( From 0c337a5def004a9d4aaaa1916c9b39e046759dd8 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Thu, 19 Mar 2020 16:50:36 -0600 Subject: [PATCH 20/41] Update examples/plot_vector_testing.py --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 1b1d2aa9..84487df6 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -1,5 +1,5 @@ """ -Testing Vectors with MatPlotCheck +Testing Vector Plots Created Using Geopandas with MatPlotCheck ================================= These are some examples of using the basic functionality of MatPlotCheck From 22d57ed0fdace546b4ccd2ab3ed7c164b084c26c Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Thu, 19 Mar 2020 16:59:30 -0600 Subject: [PATCH 21/41] a few edits to vignette --- examples/plot_vector_testing.py | 81 ++++++++++++++------------------- 1 file changed, 33 insertions(+), 48 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 84487df6..6bacc911 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -64,33 +64,23 @@ point_symb = {"Tree": "green", "Bush": "brown"} ################################################################################ -# Plotting the Geometry Objects and Storing the VectorTester Object +# Create Your Spatial Plot # ----------------------------------------------------------------- -# Now you can plot the geometry objects you've made. In order to plot them with -# a legend, you will have to loop through the geometry objects that have -# attributes and plot by attribute for each case. -# -# Once you've created the Matplotlib plot, you can collect the data! You -# can store the axes with the MatPlotCheck notebook function convert_axes, -# which will allow you to create the VectorTester object in a later cell. - -# Collecting Vector Tester objects +# Above you created several GeoPandas GeoDataFrame objects that you want +# to plot. To plot these data according to attribute value, you can group +# the geometry by attributes and plot within a loop. Once you've created +# your plot, you are ready to test it using MatPlotCheck. +# Plot your data fig, ax = plt.subplots() - -# Plotting polygon geodataframe - polygon_gdf.plot(ax=ax, color="purple") -# Plotting line geodataframe - +# Plot your data by attributes using groupby for ctype, lines in multi_line_gdf.groupby('attr'): color = line_symb[ctype] label = ctype lines.plot(color=color, ax=ax, label=label) -# Plotting point geodataframe - size = 0 for ctype, points in point_gdf.groupby('attr2'): @@ -99,65 +89,61 @@ size += 100 points.plot(color=color, ax=ax, label=label, markersize=size) -# Adding legend - +# Add a legend ax.legend(title="Legend", loc=(1.1, .1)) -vector_test_plot_hold = nb.convert_axes(plt, which_axes="current") +# DELETE THIS: vector_test_plot_hold = nb.convert_axes(plt, which_axes="current") ################################################################################ -# Creating the VectorTester Object +# Create A VectorTester Object # -------------------------------- -# Once you've stored the axes, you'll need to create the VectorTester object -# itself using the stored axes. +# Once you've created your plot, you can create a MatPlotCheck VectorTester object +# that can be used to test elements in the plot. -vector_test = VectorTester(vector_test_plot_hold) +vector_test = VectorTester(ax) ############################################################################### # # .. note:: # Each geometry type must be tested seperately in VectorTester. So, if your # plot has multiple geometry types, such as lines, polygons, and points, -# make sure to check each geometry type seperately! +# make sure to check each geometry type seperately. ############################################################################### # # .. note:: -# For these tests, you can know they passed if they don't raise an -# AssertionError. If they were to fail, they would throw an error stating -# what went wrong. +# If a test fails, matplotcheck will return an error. If the test passes, +# no message is returned. ################################################################################ -# Testing Point Values and Geometry -# --------------------------------- -# You can check that both the position of the points and there plot values are -# accurate with the tests below. For points, you can also check that the -# size of each point varies based on it's attributes. - -# Check points geometry - +# Testing Point Attribute Values and Geometry +# ------------------------------------------- +# You can check that both the position of the points on the plot and the associated +# point attribute values are +# accurate using assert_points(), assert_points_grouped_by_type() and +# assert_collection_sorted_by_markersize. If the plot uses point markers that are +# sized by attribute value, you can check that the +# size of each marker correctly relates to an attribute value. + +# Check point geometry location (x, y location) vector_test.assert_points(point_gdf) -# Check points plotted by type - +# Check points are grouped plotted by type vector_test.assert_points_grouped_by_type(point_gdf, "attr2") -# Check points size varies based on a variable. - +# Check points size is relative to a numeric attribute value vector_test.assert_collection_sorted_by_markersize(point_gdf, "attr2") ################################################################################ -# Testing Line Values and Geometry -# -------------------------------- -# Similarly to points, you can check the position and plot values of line -# geometries are accurate with the tests below. - -# Check lines geometry +# Test Line Attribute Values and Coordinate Information (x, y) +# ------------------------------------------------------------ +# You can also test the position and plot values of line +# geometries. +# Check line geometry vector_test.assert_lines(multi_line_gdf) # Check lines plotted by type - vector_test.assert_lines_grouped_by_type(multi_line_gdf, "attr") ################################################################################ @@ -168,5 +154,4 @@ # check that polygons are plotted correctly! # Check Polygons - vector_test.assert_polygons(polygon_gdf) From 4bbc7f545a3c3b27aea9f3603a3177fe123d8128 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Fri, 20 Mar 2020 10:27:09 -0600 Subject: [PATCH 22/41] Added suggested changes to the vignette --- examples/plot_vector_testing.py | 39 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 6bacc911..8552c928 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -1,17 +1,17 @@ """ Testing Vector Plots Created Using Geopandas with MatPlotCheck -================================= +============================================================== -These are some examples of using the basic functionality of MatPlotCheck -to test vector plots in Python. +This vignette will show you how to use Matplotcheck to test spatial vector data +plots created using Geopandas. """ ################################################################################ # Setup # ----- -# You will start by importing the required packages and geometry objects -# to plot and test. +# To begin, import the libraries that you need. + import matplotlib.pyplot as plt import geopandas as gpd @@ -23,7 +23,7 @@ # Create geometry objects -# Polygon GDF +# Create a polygon GeoDataFrame coords = [(2, 4), (2, 4.25), (4.25, 4.25), (4.25, 2), (2, 2)] coords_b = [(i[0]+5, i[1]+7) for i in coords] polygon_a = Polygon(coords) @@ -32,19 +32,18 @@ [1, 2], geometry=[polygon_a, polygon_b], crs="epsg:4326") -# Line GDF +# Create a line GeoDataFrame linea = LineString([(1, 1), (2, 2), (3, 2), (5, 3)]) lineb = LineString([(3, 4), (5, 7), (12, 2), (10, 5), (9, 7.5)]) line_gdf = gpd.GeoDataFrame([1, 2], geometry=[linea, lineb], crs="epsg:4326") -# MultiLine GDF - +# Create a multiline GeoDataFrame linec = LineString([(2, 1), (3, 1), (4, 1), (5, 2)]) multi_line_gdf = gpd.GeoDataFrame(geometry=gpd.GeoSeries( [line_gdf.unary_union, linec]), crs="epsg:4326") multi_line_gdf["attr"] = ["road", "stream"] -# Point GDF +# Create a point GeoDataFrame points = pd.DataFrame( { @@ -58,7 +57,7 @@ ) point_gdf["attr2"] = ["Tree", "Tree", "Bush", "Bush", "Bush"] -# Symbology for the legend +# Create symbology dictionary to use in the legend line_symb = {"road": "black", "stream": "blue"} point_symb = {"Tree": "green", "Bush": "brown"} @@ -66,10 +65,10 @@ ################################################################################ # Create Your Spatial Plot # ----------------------------------------------------------------- -# Above you created several GeoPandas GeoDataFrame objects that you want +# Above you created several GeoPandas GeoDataFrame objects that you want # to plot. To plot these data according to attribute value, you can group -# the geometry by attributes and plot within a loop. Once you've created -# your plot, you are ready to test it using MatPlotCheck. +# the geometry by attributes and plot within a loop. Once you've created +# your plot, you are ready to test it using MatPlotCheck. # Plot your data fig, ax = plt.subplots() @@ -90,9 +89,7 @@ points.plot(color=color, ax=ax, label=label, markersize=size) # Add a legend -ax.legend(title="Legend", loc=(1.1, .1)) - -# DELETE THIS: vector_test_plot_hold = nb.convert_axes(plt, which_axes="current") +ax.legend(title="Legend", loc=(1.1, .1)); ################################################################################ # Create A VectorTester Object @@ -112,16 +109,16 @@ ############################################################################### # # .. note:: -# If a test fails, matplotcheck will return an error. If the test passes, +# If a test fails, matplotcheck will return an error. If the test passes, # no message is returned. ################################################################################ # Testing Point Attribute Values and Geometry # ------------------------------------------- -# You can check that both the position of the points on the plot and the associated +# You can check that both the position of the points on the plot and the associated # point attribute values are -# accurate using assert_points(), assert_points_grouped_by_type() and -# assert_collection_sorted_by_markersize. If the plot uses point markers that are +# accurate using assert_points(), assert_points_grouped_by_type() and +# assert_collection_sorted_by_markersize. If the plot uses point markers that are # sized by attribute value, you can check that the # size of each marker correctly relates to an attribute value. From 6538145d1844692f93efbacd6e6ba84fac5e1cc2 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Fri, 20 Mar 2020 10:28:56 -0600 Subject: [PATCH 23/41] Changelog updates --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86f7f067..2920373e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +* Added a vignette for the VectorTester module (@nkorinek, #208) * Created functions to test point geometries in VectorTester (@nkorinek, #176) * made `assert_string_contains()` accept correct strings with spaces in them (@nkorinek, #182) * added contributors file and updated README to remove that information (@nkorinek, #121) From c3b5dc149f516dec3466de458eb039bff35a6a48 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Fri, 20 Mar 2020 10:32:18 -0600 Subject: [PATCH 24/41] Codacy changes --- examples/plot_vector_testing.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 8552c928..d3483c2d 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -12,14 +12,12 @@ # ----- # To begin, import the libraries that you need. - +import numpy as np +import pandas as pd import matplotlib.pyplot as plt +from shapely.geometry import Polygon, LineString import geopandas as gpd -import pandas as pd from matplotcheck.vector import VectorTester -import matplotcheck.notebook as nb -from shapely.geometry import Polygon, LineString -import numpy as np # Create geometry objects From 567fd9dc43906ee02bfb77ac1fb9922672cd6836 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Fri, 20 Mar 2020 12:12:30 -0600 Subject: [PATCH 25/41] Added example of where one would hypothetically use the funciton. --- examples/plot_vector_testing.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index d3483c2d..3d06d938 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -89,6 +89,12 @@ # Add a legend ax.legend(title="Legend", loc=(1.1, .1)); +# If you were running this in a notebook, the commented out line below would +# store the matplotlib object. However, in this example, you can just grab the +# axes object directly. + +# plot_1_hold = nb.convert_axes(plt, which_axes="current") + ################################################################################ # Create A VectorTester Object # -------------------------------- From 884fb611b1dad0e9fa19406d28e0d9c844b2cb93 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Fri, 20 Mar 2020 16:26:00 -0600 Subject: [PATCH 26/41] Update examples/plot_vector_testing.py Co-Authored-By: Leah Wasser --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 3d06d938..ec5b1c01 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -96,7 +96,7 @@ # plot_1_hold = nb.convert_axes(plt, which_axes="current") ################################################################################ -# Create A VectorTester Object +# Create A MatPlotCheck VectorTester Object # -------------------------------- # Once you've created your plot, you can create a MatPlotCheck VectorTester object # that can be used to test elements in the plot. From 7b8526b1cce431f74f2425477409882be80740ad Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Fri, 20 Mar 2020 16:26:10 -0600 Subject: [PATCH 27/41] Update examples/plot_vector_testing.py Co-Authored-By: Leah Wasser --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index ec5b1c01..ea59b7cb 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -117,7 +117,7 @@ # no message is returned. ################################################################################ -# Testing Point Attribute Values and Geometry +# Test Point Attribute Values and Geometry xy Locations # ------------------------------------------- # You can check that both the position of the points on the plot and the associated # point attribute values are From 73517fa3fb2e8c592b7482ab6a793eba2a920965 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Fri, 20 Mar 2020 16:26:18 -0600 Subject: [PATCH 28/41] Update examples/plot_vector_testing.py Co-Authored-By: Leah Wasser --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index ea59b7cb..b4ef8f81 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -122,7 +122,7 @@ # You can check that both the position of the points on the plot and the associated # point attribute values are # accurate using assert_points(), assert_points_grouped_by_type() and -# assert_collection_sorted_by_markersize. If the plot uses point markers that are +# ``assert_collection_sorted_by_markersize``. If the plot uses point markers that are # sized by attribute value, you can check that the # size of each marker correctly relates to an attribute value. From 523a065d6d2043d17dffafbd86eced2c8138b529 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Fri, 20 Mar 2020 16:27:45 -0600 Subject: [PATCH 29/41] Update examples/plot_vector_testing.py Co-Authored-By: Leah Wasser --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index b4ef8f81..b0cb38b0 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -121,7 +121,7 @@ # ------------------------------------------- # You can check that both the position of the points on the plot and the associated # point attribute values are -# accurate using assert_points(), assert_points_grouped_by_type() and +# accurate using ``assert_points()``, ``assert_points_grouped_by_type()`` and # ``assert_collection_sorted_by_markersize``. If the plot uses point markers that are # sized by attribute value, you can check that the # size of each marker correctly relates to an attribute value. From f6df4575c838d395000f55c2e8ed822415d295e4 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Fri, 20 Mar 2020 16:28:09 -0600 Subject: [PATCH 30/41] Update examples/plot_vector_testing.py Co-Authored-By: Leah Wasser --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index b0cb38b0..9cce80fb 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -113,7 +113,7 @@ ############################################################################### # # .. note:: -# If a test fails, matplotcheck will return an error. If the test passes, +# Most tests are created as assert statements. Thus, if a test fails, matplotcheck will return an error. If the test passes, # no message is returned. ################################################################################ From e3e44c164fd1166f05f5674aa1fcb7dd1188ba16 Mon Sep 17 00:00:00 2001 From: Nathan Korinek Date: Fri, 20 Mar 2020 16:28:24 -0600 Subject: [PATCH 31/41] Update examples/plot_vector_testing.py Co-Authored-By: Leah Wasser --- examples/plot_vector_testing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 9cce80fb..c314c79f 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -108,7 +108,7 @@ # .. note:: # Each geometry type must be tested seperately in VectorTester. So, if your # plot has multiple geometry types, such as lines, polygons, and points, -# make sure to check each geometry type seperately. +# make sure to check each geometry type separately. ############################################################################### # From bc38d6fd89940e9ef563b1a50b894bbc43606d1f Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 23 Mar 2020 12:04:46 -0600 Subject: [PATCH 32/41] Changed how the markersize test is run, and fixed some typos and documentation issues. --- examples/plot_vector_testing.py | 40 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 3d06d938..60725439 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -53,12 +53,12 @@ point_gdf = gpd.GeoDataFrame( {"A": np.arange(5), "B": np.arange(5)}, geometry=gpd.points_from_xy(points.lon, points.lat), crs="epsg:4326" ) -point_gdf["attr2"] = ["Tree", "Tree", "Bush", "Bush", "Bush"] +point_gdf["size"] = [100, 100, 300, 300, 500] # Create symbology dictionary to use in the legend line_symb = {"road": "black", "stream": "blue"} -point_symb = {"Tree": "green", "Bush": "brown"} +point_symb = {100: "purple", 300: "green", 500: "brown"} ################################################################################ # Create Your Spatial Plot @@ -78,13 +78,10 @@ label = ctype lines.plot(color=color, ax=ax, label=label) -size = 0 - -for ctype, points in point_gdf.groupby('attr2'): +for ctype, points in point_gdf.groupby('size'): color = point_symb[ctype] label = ctype - size += 100 - points.plot(color=color, ax=ax, label=label, markersize=size) + points.plot(color=color, ax=ax, label=label, markersize=ctype) # Add a legend ax.legend(title="Legend", loc=(1.1, .1)); @@ -95,6 +92,17 @@ # plot_1_hold = nb.convert_axes(plt, which_axes="current") +############################################################################### +# +# .. note:: +# If you are testing a plot that is created in a Jupyter Notebook - for +# example a student assignment - and you want to get a copy of the student's +# figure created in a cell you can use the following approach: +# ``ax_object = nb.convert_axes(plt, which_axes="current")`` +# then in the cell below where you write your tests, you can create a +# PlotTester object by calling: +# ``PlotTester(ax_object)`` + ################################################################################ # Create A VectorTester Object # -------------------------------- @@ -122,18 +130,26 @@ # You can check that both the position of the points on the plot and the associated # point attribute values are # accurate using assert_points(), assert_points_grouped_by_type() and -# assert_collection_sorted_by_markersize. If the plot uses point markers that are -# sized by attribute value, you can check that the -# size of each marker correctly relates to an attribute value. +# assert_collection_sorted_by_markersize(). +# +# To check the geometry locations, you can call assert_points() and prove the +# expected points data, which in this case is the point_gdf object. +# +# If the plot uses point markers that are sized by attribute value, you can +# check that the size of each marker correctly relates to an attribute value by +# providing the geometry, point_gdf here, and the attribute the size is based +# off of, which is the 'size' column in this case. + + # Check point geometry location (x, y location) vector_test.assert_points(point_gdf) # Check points are grouped plotted by type -vector_test.assert_points_grouped_by_type(point_gdf, "attr2") +vector_test.assert_points_grouped_by_type(point_gdf, "size") # Check points size is relative to a numeric attribute value -vector_test.assert_collection_sorted_by_markersize(point_gdf, "attr2") +vector_test.assert_collection_sorted_by_markersize(point_gdf, "size") ################################################################################ # Test Line Attribute Values and Coordinate Information (x, y) From 7ec0998560aa99785d12bfe74bc53b9490287e85 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 23 Mar 2020 12:41:45 -0600 Subject: [PATCH 33/41] Fixing issues with the underline lengths --- examples/plot_vector_testing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 64367513..18d7d5e5 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -62,7 +62,7 @@ ################################################################################ # Create Your Spatial Plot -# ----------------------------------------------------------------- +# ------------------------ # Above you created several GeoPandas GeoDataFrame objects that you want # to plot. To plot these data according to attribute value, you can group # the geometry by attributes and plot within a loop. Once you've created @@ -105,7 +105,7 @@ ################################################################################ # Create A MatPlotCheck VectorTester Object -# -------------------------------- +# ----------------------------------------- # Once you've created your plot, you can create a MatPlotCheck VectorTester object # that can be used to test elements in the plot. @@ -126,7 +126,7 @@ ################################################################################ # Test Point Attribute Values and Geometry xy Locations -# ------------------------------------------- +# ----------------------------------------------------- # You can check that both the position of the points on the plot and the associated # point attribute values are # accurate using assert_points(), assert_points_grouped_by_type() and From 0d3572377b5016300bd2b6e81effb9527dfef8c5 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Mon, 23 Mar 2020 16:00:29 -0600 Subject: [PATCH 34/41] Changelog rewording --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1756331..1774e205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -* Added a vignette for the VectorTester module (@nkorinek, #208) +* Added a vignette for the VectorTester module functions (@nkorinek, #208) * Created tests for the vector module (@nkorinek, #209) * Created functions to test point geometries in VectorTester (@nkorinek, #176) * made `assert_string_contains()` accept correct strings with spaces in them (@nkorinek, #182) From 25f863f4a77ea5279068d3d6bde1f987d73f4209 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Thu, 2 Apr 2020 14:41:53 -0600 Subject: [PATCH 35/41] Undoing changes --- dev-requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 85229890..4b900499 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -11,4 +11,3 @@ setuptools==46.1.3 pre-commit==1.20.0 pip==19.0.3 descartes==1.1.0 -seaborn==0.10.0 From 4878219238f62b55b570b3af40b0137cef4291f3 Mon Sep 17 00:00:00 2001 From: nkorinek Date: Fri, 3 Apr 2020 11:54:44 -0600 Subject: [PATCH 36/41] Merge --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dc9406a..fafb88ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -* Added a vignette for the VectorTester module functions (@nkorinek, #208) +* Added a vignette for the VectorTester module functions. (@nkorinek, #208) * Added functions to get and assert the midpoint values of bins in a histogram (@nkorinek, #184) * Created tests for the autograde module (@nkorinek, #105) * Created tests for the vector module (@nkorinek, #209) From 2c01d02f503b58b11ccc0d9fc5bd19928fcc89fc Mon Sep 17 00:00:00 2001 From: nkorinek Date: Fri, 10 Apr 2020 16:24:38 -0600 Subject: [PATCH 37/41] Added in changes discussed on github --- examples/plot_vector_testing.py | 91 ++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 30 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 18d7d5e5..91bf8f28 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -19,16 +19,21 @@ import geopandas as gpd from matplotcheck.vector import VectorTester -# Create geometry objects +################################################################################ +# Create Geometry Objects +# ----------------------- +# To run this test, you first must plot some example data. Below are GeoPandas +# dataframes created to replicate data that may be used in an earth data +# science exercise. The polygons could be study areas, the lines could be roads +# and streams near those study areas, and the points could be measurments +# within the study areas. # Create a polygon GeoDataFrame coords = [(2, 4), (2, 4.25), (4.25, 4.25), (4.25, 2), (2, 2)] coords_b = [(i[0]+5, i[1]+7) for i in coords] -polygon_a = Polygon(coords) -polygon_b = Polygon(coords_b) polygon_gdf = gpd.GeoDataFrame( - [1, 2], geometry=[polygon_a, polygon_b], crs="epsg:4326") - + [1, 2], geometry=[Polygon(coords), Polygon(coords_b)], crs="epsg:4326") +polygon_gdf["attr"] = ["Area 1", "Area 2"] # Create a line GeoDataFrame linea = LineString([(1, 1), (2, 2), (3, 2), (5, 3)]) @@ -51,7 +56,8 @@ ) point_gdf = gpd.GeoDataFrame( - {"A": np.arange(5), "B": np.arange(5)}, geometry=gpd.points_from_xy(points.lon, points.lat), crs="epsg:4326" + {"A": np.arange(5), "B": np.arange(5)}, + geometry=gpd.points_from_xy(points.lon, points.lat), crs="epsg:4326" ) point_gdf["size"] = [100, 100, 300, 300, 500] @@ -72,12 +78,13 @@ fig, ax = plt.subplots() polygon_gdf.plot(ax=ax, color="purple") -# Plot your data by attributes using groupby +# Plot your line data by attributes using groupby for ctype, lines in multi_line_gdf.groupby('attr'): color = line_symb[ctype] label = ctype lines.plot(color=color, ax=ax, label=label) +# Plot your points data by size using groupby for ctype, points in point_gdf.groupby('size'): color = point_symb[ctype] label = ctype @@ -86,28 +93,11 @@ # Add a legend ax.legend(title="Legend", loc=(1.1, .1)); -# If you were running this in a notebook, the commented out line below would -# store the matplotlib object. However, in this example, you can just grab the -# axes object directly. - -# plot_1_hold = nb.convert_axes(plt, which_axes="current") - -############################################################################### -# -# .. note:: -# If you are testing a plot that is created in a Jupyter Notebook - for -# example a student assignment - and you want to get a copy of the student's -# figure created in a cell you can use the following approach: -# ``ax_object = nb.convert_axes(plt, which_axes="current")`` -# then in the cell below where you write your tests, you can create a -# PlotTester object by calling: -# ``PlotTester(ax_object)`` - ################################################################################ # Create A MatPlotCheck VectorTester Object # ----------------------------------------- -# Once you've created your plot, you can create a MatPlotCheck VectorTester object -# that can be used to test elements in the plot. +# Once you've created your plot, you can create a MatPlotCheck VectorTester +# object that can be used to test elements in the plot. vector_test = VectorTester(ax) @@ -121,14 +111,15 @@ ############################################################################### # # .. note:: -# Most tests are created as assert statements. Thus, if a test fails, matplotcheck will return an error. If the test passes, -# no message is returned. +# Most tests are created as assert statements. Thus, if a test fails, +# matplotcheck will return an error. If the test passes, no message is +# returned. ################################################################################ # Test Point Attribute Values and Geometry xy Locations # ----------------------------------------------------- -# You can check that both the position of the points on the plot and the associated -# point attribute values are +# You can check that both the position of the points on the plot and the +# associated point attribute values are # accurate using assert_points(), assert_points_grouped_by_type() and # assert_collection_sorted_by_markersize(). # @@ -172,3 +163,43 @@ # Check Polygons vector_test.assert_polygons(polygon_gdf) + +################################################################################ +# Access the Axes object in a Jupyter Notebook +# -------------------------------------------- +# MatPlotCheck can be used to help grade Jupyter Notebooks as well. The main +# difference is in how you would store the Axes from the plot you are grading. +# Below is an example of how you could store the Axes of a plot you are hoping +# to grade in a notebook. + +# First, import the Notebook module from MatPlotCheck +import matplotcheck.notebook as nb + +# Plot your data +fig, ax = plt.subplots() +polygon_gdf.plot(ax=ax, color="purple") + +# Plot your line data by attributes using groupby +for ctype, lines in multi_line_gdf.groupby('attr'): + color = line_symb[ctype] + label = ctype + lines.plot(color=color, ax=ax, label=label) + +# Plot your points data by size using groupby +for ctype, points in point_gdf.groupby('size'): + color = point_symb[ctype] + label = ctype + points.plot(color=color, ax=ax, label=label, markersize=ctype) + +# Add a legend +ax.legend(title="Legend", loc=(1.1, .1)); + +# HERE'S WHERE YOU STORE THE PLOT! +# This line at the end of a cell you are expecting a plot in will store any +# matplotlib plot made in that cell so you can test it at a later time. +plot_test_hold = nb.convert_axes(plt, which_axes="current") + +# This can then be turned into a VectorTester object. +vector_test = VectorTester(plot_test_hold) + +# Now you can run the tests as you did earlier! From 3b4912aea2ab4db3b44c05e96ef7994c4eaf56ef Mon Sep 17 00:00:00 2001 From: nkorinek Date: Tue, 21 Apr 2020 17:02:40 -0600 Subject: [PATCH 38/41] Added in formatting changes requested on github --- examples/plot_vector_testing.py | 89 +++++++++++++++++---------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index 91bf8f28..fc90f5db 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -1,20 +1,20 @@ """ -Testing Vector Plots Created Using Geopandas with MatPlotCheck -============================================================== +Test Plots of Vector Data (Created Using GeoPandas) with Matplotcheck +===================================================================== -This vignette will show you how to use Matplotcheck to test spatial vector data -plots created using Geopandas. +This vignette will show you how to use Matplotcheck to test plots of spatial +vector data created using GeoPandas. """ ################################################################################ -# Setup -# ----- +# Import Packages +# --------------- # To begin, import the libraries that you need. +import matplotlib.pyplot as plt import numpy as np import pandas as pd -import matplotlib.pyplot as plt from shapely.geometry import Polygon, LineString import geopandas as gpd from matplotcheck.vector import VectorTester @@ -22,11 +22,11 @@ ################################################################################ # Create Geometry Objects # ----------------------- -# To run this test, you first must plot some example data. Below are GeoPandas -# dataframes created to replicate data that may be used in an earth data -# science exercise. The polygons could be study areas, the lines could be roads -# and streams near those study areas, and the points could be measurments -# within the study areas. +# To run this test, you must first plot some example data. Below are GeoPandas +# dataframes created to replicate data that may be used in an earth or +# environmental data science exercise. The polygons could be study areas, +# while the lines could be roads and streams near those study areas. The points +# could be measurements within the study areas. # Create a polygon GeoDataFrame coords = [(2, 4), (2, 4.25), (4.25, 4.25), (4.25, 2), (2, 2)] @@ -47,7 +47,6 @@ multi_line_gdf["attr"] = ["road", "stream"] # Create a point GeoDataFrame - points = pd.DataFrame( { "lat": np.array([1, 2, 1, 0, 4]), @@ -62,7 +61,6 @@ point_gdf["size"] = [100, 100, 300, 300, 500] # Create symbology dictionary to use in the legend - line_symb = {"road": "black", "stream": "blue"} point_symb = {100: "purple", 300: "green", 500: "brown"} @@ -71,8 +69,8 @@ # ------------------------ # Above you created several GeoPandas GeoDataFrame objects that you want # to plot. To plot these data according to attribute value, you can group -# the geometry by attributes and plot within a loop. Once you've created -# your plot, you are ready to test it using MatPlotCheck. +# the geometry by attributes and plot within a loop. Once you have created your +# plot, you will be ready to test it using Matplotcheck # Plot your data fig, ax = plt.subplots() @@ -94,10 +92,11 @@ ax.legend(title="Legend", loc=(1.1, .1)); ################################################################################ -# Create A MatPlotCheck VectorTester Object +# Create A Matplotcheck VectorTester Object # ----------------------------------------- -# Once you've created your plot, you can create a MatPlotCheck VectorTester -# object that can be used to test elements in the plot. +# Once you have created your plot, you can create a Matplotcheck VectorTester +# object that can be used to test elements in the plot by providing the ax +# object to the VectorTester function. vector_test = VectorTester(ax) @@ -112,19 +111,20 @@ # # .. note:: # Most tests are created as assert statements. Thus, if a test fails, -# matplotcheck will return an error. If the test passes, no message is +# Matplotcheck will return an error. If the test passes, no message is # returned. ################################################################################ -# Test Point Attribute Values and Geometry xy Locations -# ----------------------------------------------------- +# Test Point Attribute Values and Geometry (x, y Locations) +# --------------------------------------------------------- # You can check that both the position of the points on the plot and the # associated point attribute values are # accurate using assert_points(), assert_points_grouped_by_type() and # assert_collection_sorted_by_markersize(). # -# To check the geometry locations, you can call assert_points() and prove the -# expected points data, which in this case is the point_gdf object. +# To check the geometry locations, you can call assert_points() and check the +# plot data against the expected points data, which in this case is the +# point_gdf object. # # If the plot uses point markers that are sized by attribute value, you can # check that the size of each marker correctly relates to an attribute value by @@ -143,36 +143,37 @@ vector_test.assert_collection_sorted_by_markersize(point_gdf, "size") ################################################################################ -# Test Line Attribute Values and Coordinate Information (x, y) -# ------------------------------------------------------------ +# Test Line Attribute Values and Geometry (Coordinate Information) +# ---------------------------------------------------------------- # You can also test the position and plot values of line # geometries. # Check line geometry vector_test.assert_lines(multi_line_gdf) -# Check lines plotted by type +# Check lines are plotted by type vector_test.assert_lines_grouped_by_type(multi_line_gdf, "attr") ################################################################################ -# Testing Polygon Geometry -# ------------------------ -# Currently, MatPlotCheck is unable to check that polygons were plotted by type. -# Eventually this will be supported. For the time being though, you can still -# check that polygons are plotted correctly! +# Testing Polygon Geometries +# -------------------------- +# Currently, Matplotcheck is unable to check that polygons were plotted by type. +# Eventually this will be supported. For now, you can check that polygons are +# plotted correctly! # Check Polygons vector_test.assert_polygons(polygon_gdf) ################################################################################ -# Access the Axes object in a Jupyter Notebook -# -------------------------------------------- -# MatPlotCheck can be used to help grade Jupyter Notebooks as well. The main -# difference is in how you would store the Axes from the plot you are grading. -# Below is an example of how you could store the Axes of a plot you are hoping -# to grade in a notebook. - -# First, import the Notebook module from MatPlotCheck +# Access Axes Objects in a Jupyter Notebook +# ----------------------------------------- +# 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 your data @@ -194,12 +195,12 @@ # Add a legend ax.legend(title="Legend", loc=(1.1, .1)); -# HERE'S WHERE YOU STORE THE PLOT! -# This line at the end of a cell you are expecting a plot in will store any -# matplotlib plot made in that cell so you can test it at a later time. +# 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. plot_test_hold = nb.convert_axes(plt, which_axes="current") -# This can then be turned into a VectorTester object. +# This object can then be turned into a VectorTester object. vector_test = VectorTester(plot_test_hold) # Now you can run the tests as you did earlier! From bde56059c8d1a53536dd6c5d7eca7cb152c2f18a Mon Sep 17 00:00:00 2001 From: nkorinek Date: Wed, 22 Apr 2020 12:44:47 -0600 Subject: [PATCH 39/41] Fixing a final few typos! --- examples/plot_vector_testing.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index fc90f5db..e153a4bf 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -70,7 +70,7 @@ # Above you created several GeoPandas GeoDataFrame objects that you want # to plot. To plot these data according to attribute value, you can group # the geometry by attributes and plot within a loop. Once you have created your -# plot, you will be ready to test it using Matplotcheck +# plot, you will be ready to test it using Matplotcheck. # Plot your data fig, ax = plt.subplots() @@ -128,8 +128,8 @@ # # If the plot uses point markers that are sized by attribute value, you can # check that the size of each marker correctly relates to an attribute value by -# providing the geometry, point_gdf here, and the attribute the size is based -# off of, which is the 'size' column in this case. +# providing the geometry (in this example, point_gdf), and the attribute the +# size is based off of, which is the 'size' column in this case. @@ -169,9 +169,8 @@ # ----------------------------------------- # 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. +# 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 From cf5c83b23e5f742d1cd3d37a8d6fc6a303f4c73d Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Fri, 24 Apr 2020 13:31:34 -0600 Subject: [PATCH 40/41] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 042737e9..1c6f1f96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -* Added a vignette for the VectorTester module functions. (@nkorinek, #208) +* Add a vignette for testing vector data plots. (@nkorinek, #208) * Add `pillow` as a dev requirement (@lwasser, #253) * Removed the `m2r` package from MatPlotCheck (@nkorinek, #247) * Made `assert_string_contains()` accept a string instead of a list (@nkorinek, #53) From da924a0e4374b1563120b517ae7a935fb07aa5a5 Mon Sep 17 00:00:00 2001 From: Leah Wasser Date: Fri, 24 Apr 2020 13:34:22 -0600 Subject: [PATCH 41/41] minor fix --- examples/plot_vector_testing.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/plot_vector_testing.py b/examples/plot_vector_testing.py index e153a4bf..4b70923e 100644 --- a/examples/plot_vector_testing.py +++ b/examples/plot_vector_testing.py @@ -107,12 +107,6 @@ # plot has multiple geometry types, such as lines, polygons, and points, # make sure to check each geometry type separately. -############################################################################### -# -# .. note:: -# Most tests are created as assert statements. Thus, if a test fails, -# Matplotcheck will return an error. If the test passes, no message is -# returned. ################################################################################ # Test Point Attribute Values and Geometry (x, y Locations) @@ -132,7 +126,6 @@ # size is based off of, which is the 'size' column in this case. - # Check point geometry location (x, y location) vector_test.assert_points(point_gdf) @@ -142,10 +135,17 @@ # Check points size is relative to a numeric attribute value vector_test.assert_collection_sorted_by_markersize(point_gdf, "size") +############################################################################### +# +# .. note:: +# Most tests are created as assert statements. Thus, if a test fails, +# Matplotcheck will return an error. If the test passes, no message is +# returned. + ################################################################################ # Test Line Attribute Values and Geometry (Coordinate Information) # ---------------------------------------------------------------- -# You can also test the position and plot values of line +# You can also test the position and attributes of line # geometries. # Check line geometry