matplotcheck package¶
Submodules¶
matplotcheck.autograde module¶
matplotcheck.autograde¶
Wrapper functions that run and track the passing status of matplotcheck functions and provide formatted results of tests.

matplotcheck.autograde.
output_results
(results)[source]¶ Print a formatted message containing the total number of points summed across a list of dictionaries with results from one or more tests
Parameters: results (list of dictionaries with the following keys:) – points : int or float : points assigned based on test results pass : bool : passing status of test function description : str : test function name that was run message : str : custom message returned based on passing status traceback : AssertionError : returned from test function when pass is False Returns: points – Number of points summed across points in results list Return type: int or float

matplotcheck.autograde.
run_test
(func, points, *args, correct_message='default correct', error_message='default error', **kwargs)[source]¶ Run a predefined test function and creates a dictionary containing the results of the test
Parameters:  func (function or method) – Predefined test function to run
 points (int or float) – Number of points assigned for passing test
 *args – Variable arguments passed to test function
 correct_message (str) – Custom message returned with passing test
 error_message (str) – Custom message returned with failing test
 **kwargs – Keyword arguments passed to test function
Returns: results – points : int or float : points assigned based on test results pass : bool : passing status of test function description : str : test function name that was run message : str : custom message returned based on passing status traceback : AssertionError : returned from test function when pass is False
Return type: dict with the following keys:
matplotcheck.base module¶
matplotcheck.base¶
Base plot checking class and methods that should apply to all plots whether they are spatial or not.

class
matplotcheck.base.
PlotTester
(ax)[source]¶ Bases:
object
Object to grab elements from Matplotlib plots Temporarily removing parameters and returns as it’s breaking sphinx
Parameters: axis (mpl axis object) – 
assert_axis_label_contains
(axis='x', lst=[])[source]¶ Asserts axis label contains each of the strings in lst. Tests x or y axis based on ‘axis’ param. Not case sensitive
Parameters:  axis (string) – One of the following [‘x’,’y’] stated which axis label to be tested
 lst (list) – List of strings to be searched for in axis label.
If
lst == []
: assertion passes. Iflst = None
, assertion passes.
Returns: Nothing if axis label contains strings in lst. Otherwise throws
AssertionError
Return type: None

assert_axis_off
(m='Axis lines are displayed on plot')[source]¶ Asserts one of the three cases holds true with error message m: 1) axis have been turned off 2) both x and y axis have visibility set to false 3) both x and y axis ticks have been set to empty lists
Parameters: m (string) – error message if assertion is not met Returns: Nothing if axis lines are not displayed on plot. Otherwise throws AssertionError
with message mReturn type: None
Asserts that Axes ax contains strings as expected in strings_exp. strings_exp is a list of lists. Each internal list is a list of strings where at least one string must be in the caption, barring capitalization. For example,
assert_caption_contains([['A'], ['B'], ['C']])
checks that all of'A'
,'B'
, and'C'
exist in the caption. Alternatively,assert_caption_contains([['A', 'B', 'C']])
checks that any one of'A'
,'B'
, and'C'
exist in the caption.Parameters: strings_exp (list of lists.) – list of lists in which each internal list is a list of strings. If strings_exp = None
, assertion passes. Ifstrings_exp == []
, assertion passes.Returns: Nothing if caption contains strings matching strings_exp, otherwise throws AssertionError
Return type: None Notes
This function enforces that no found strings can overlap. Once a string is found, it is removed from the caption so that another string does not match on overlapping text. Therefore, in some cases, the order of strings_exp does matter.

assert_equal_xlims_ylims
(m='xlims and ylims are not equal')[source]¶ Assert the x and y lims of Axes ax are exactly equal to each other
Parameters: m (string) – Error message if assertion is not met that is shown to the user. Returns: Nothing if limits are equal, otherwise throws AssertionError
with message mReturn type: None

assert_legend_labels
(labels_exp)[source]¶ Asserts legends on ax have the correct entry labels
Parameters: labels_exp (list of strings) – Each string is an expected legend entry label. Checks that the legend entry labels match exactly (except for case). Returns: Nothing if legend labeles match labels_exp, otherwise throws AssertionError
Return type: None Notes
If there are multiple legends, it combines all the legend labels into one set and checks that set against the list labels_exp

assert_legend_no_overlay_content
(m='Legend overlays plot window')[source]¶ Asserts that each legend does not overlay plot window
Parameters: m (string) – error message if assertion is not met Returns: Nothing if legend does not overlay plot window. Otherwise throws AssertionError
with message mReturn type: None

assert_legend_titles
(titles_exp)[source]¶ Asserts legend titles contain expected text in titles_exp list.
Parameters: titles_exp (list of strings) – Each string is expected be be in one legend title. The number of strings is equal to the number of expected legends. Returns: Nothing if legend titles contain expected text, otherwise throws AssertionError
Return type: None

assert_lims
(lims_expected, axis='x')[source]¶ Assert the lims of ax match lims_expected. Tests x or y axis based on ‘axis’ param
Parameters:  lims_expected (list of numbers (float or int)) – List of length 2 containing expected min and max vals for axis limits
 axis (string) – From [‘x’,’y’], which axis to be tested
Returns: Nothing if lims_expected matches the limits of ax, otherwise throws
AssertionError
Return type: None

assert_lims_range
(lims_range, axis='x')[source]¶ Asserts axis limits fall within lims_range (INCLUSIVE).
Parameters:  lims_range (tuple of tuples.) – if axis == ‘x’: first tuple is range the left x limit must be in, second tuple is the range the right x limit must be in if axis == ‘y’: first tuple is range the bottom y limit must be in, second tuple is the range the top x limit must be in
 axis (string) – from list [‘x’,’y’] declaring which axis to be tested
Returns: Nothing if axis limits fall within lims_range, otherwise throws
AssertionError
Return type: None

assert_line
(slope_exp, intercept_exp, xtime=False, m='Expected line not displayed', m2='Line does not cover data set')[source]¶ Asserts that there exists a line on Axes ax with slope slope_exp and yintercept intercept_exp and goes at least from x coordinate min_val to x coordinate max_val
Parameters:  slope_exp (float) – Expected slope of line
 intercept_exp (float) – Expeted y intercept of line
 xtime (boolean) – Set
True
if xaxis values are datetime  m (string) – If line does not exist, m is displayed as the error message.
 m2 (string) – If line exists but does not cover dataset, m2 is displayed as the error message.
Returns: Nothing if line exists and covers dataset, otherwise throws
AssertionError
with message m or m2Return type: None

assert_lines_of_type
(line_types)[source]¶ Asserts each line of type in line_types exist on ax
Parameters: line_types (list of strings) – Acceptable strings in line_types are as follows ['regression', 'onetoone']
.Returns: Nothing if each line of type in line_types exists on ax, otherwise throws AssertionError
.Return type: None Notes
If line_types is empty, assertion is passed.

assert_no_legend_overlap
(m='Legends overlap eachother')[source]¶ When multiple legends on ax, asserts that there are no two legends in ax that overlap each other
Parameters: m (string) – If two legends overlap, m is displayed as the error message. Returns: Nothing if no legends overlap, otherwise throws AssertionError
with message mReturn type: None

assert_num_bins
(n=3, which_bins='positive')[source]¶ Asserts number of bins of type which_bins is at least n
Parameters:  n (int) – Minimum number of bins of type which_bin
 which_bins (string) – Value may be one of: [‘negative’, ‘positive’] ‘negative’: all bins with values centered at a positive value ‘positite’: all bins with values centered at a negative value
Returns: Nothing if number of bins of type which_bins is at least n, otherwise throws
AssertionError
.Return type: None

assert_plot_type
(plot_type=None)[source]¶ Asserts Axes ax contains the type of plot specified in plot_type. if plot_type is
None
, assertion is passed.Parameters: plot_type (string) – String specifying the expected plot type. Options: scatter, bar, line Returns: Nothing if Plot matches plot_type, otherwise throws AssertionError
Return type: None

assert_title_contains
(lst, title_type='either')[source]¶ Asserts title contains each string in lst. Whether we test the axes title or figure title is described in title_type.
Parameters:  lst (list) – List of strings to be searched for in title. strings must be lower case.
 title_type (string) – One of the following strings [“figure”, “axes”, “either”] figure: only the figure title (suptitle) will be tested ‘axes’: only the axes title (suptitle) will be tested ‘either’: either the figure title or axes title will pass this assertion. The combined title will be tested.
Returns: Nothing if every element of lst exists in title, otherwise throws
AssertionError
Return type: None

assert_xlabel_ydata
(xy_expected, xcol, ycol, m='Incorrect Data')[source]¶ Asserts that the numbers in x labels and y values in Axes ax match xy_expected.
Parameters:  xy_expected (pandas.DataFrame) – Pandas DataFrame that contains data
 xcol (string) – Column title containing xaxis data
 ycol (string) – Column title containing yaxis data
 m (string) – If assertion fails, m is displayed as the error message.
Returns: Nothing if no legends overlap, otherwise throws
AssertionError
with message mReturn type: None
Notes
This is only testing the numbers in xaxis labels.

assert_xydata
(xy_expected, xcol=None, ycol=None, points_only=False, xtime=False, xlabels=False, tolerence=0, m='Incorrect data values')[source]¶ Asserts that the x and y data of Axes ax matches xy_expected with error message m. If
xy_expected = None
, assertion is passed.Parameters:  xy_expected (pandas or geopandas dataframe) – (Required) DataFrame contains data expected to be on the plot (axis object)
 xcol (string) – (Required for non geopandas objects) Title of column in
xy_expected containing values along x_axis.
If xy_expected contains this data in ‘geometry’, set to
None
.  ycol (String) – (Required for non geopandas objects) The y column name of
xy_expected which represents values along the`y_axis` in a plot.
If xy_expected contains this data in ‘geometry’ set to
None
.  points_only (boolean,) – Set
True
to check only points, setFalse
tp check all data on plot.  xtime (boolean) – Set
True
if the aaxis contains datetime values. Matplotlib converts datetime objects to seconds? This parameter will ensure the provided x col values are converted if they are datetime elements.  xlabels (boolean) – Set
True
if using x axis labels rather than x data. Instead of comparing numbers in the xcolumn to expected, compares numbers in x labels to expected.  tolerence (float) – Measure of relative error allowed.
For example: Given a tolerance
tolerence=0.1
, an expected valuee
, and an actual valuea
, this assertsabs(a  e) < (e * 0.1)
. (This uses np.testing.assert_allclose withrtol=tolerence
andatol=inf
.)  m (string) – Error message provided to the student if assertion fails
Returns: Nothing if no legends overlap, otherwise throws
AssertionError
with message mReturn type: None
Returns matplotlib.text.Text that is located in the bottom right, just below the right side of ax If no text is found in location,
None
is returned.Returns: caption – matplotlib.text.Text if text is found in bottom right, None
if no text is foundReturn type: string

get_legends
()[source]¶ Retrieve the list of legends on ax
Returns: legends – List of matplotlib.legend.Legend objects Return type: list

get_slope_yintercept
(path_verts)[source]¶ Returns the yintercept of line based on the average slope of the line
Parameters: path_verts (list) – List of verticies that make a line on Axes ax Returns:  slope (float) – The average slope of the line defined by path_verts
 y_intercept (float) – The y intercept of the line defined by path_verts

get_titles
()[source]¶ Returns the suptitle (Figure title) and axes title of ax.
Returns:  suptitle (string) – Figure title of the Figure that the ax object is on. If figure
title is
None
, this is an empty string.  title (string) – Title on the axes. If title is
None
, this is an empty string.
 suptitle (string) – Figure title of the Figure that the ax object is on. If figure
title is

get_xy
(points_only=False, xtime=False)[source]¶ Returns a pandas dataframe with columns “x” and “y” holding the x and y coords on Axes ax
Parameters:  ax (matplotlib.axes.Axes) – Matplotlib Axes object to be tested
 points_only (boolean) – Set
True
to check only points, setFalse
to check all data on plot.  xtime (boolean) – Set equal to True if the x axis of the plot contains datetime values
Returns: df – Pandas dataframe with columns “x” and “y” containing the x and y coords of each point on Axes ax
Return type: pandas.DataFrame

legends_overlap
(b1, b2)[source]¶ Helper function for assert_no_legend_overlap. True if points of window extents for b1 and b2 overlap, False otherwise
Parameters:  b1 (list of lists) – 2x2 array containg numbers, bounding box of window extents
 b2 (list of lists) – 2x2 array containg numbers, bounding box of window extents
Returns: overlap – True if bounding boxes b1 and b2 overlap
Return type: boolean

matplotcheck.cases module¶

class
matplotcheck.cases.
PlotBasicSuite
(ax, data_exp=None, xcol=None, ycol=None, plot_type=None, line_types=None, xlabels=False, lims_equal=False, title_contains=[], title_type='either', xlabel_contains=[], ylabel_contains=[], caption_strings=[], legend_labels=None, title_points=1, xlab_points=1, ylab_points=1)[source]¶ Bases:
object
A generic object to test a basic 2d Matplotlib plot (scatter, bar, line)
Parameters:  ax (Matplotlib Axes to be tested) –
 data_exp (pandas dataframe containing plot data) –
 xcol (string column title in data_exp that contains xaxis data) –
 ycol (string column title in data_exp that contains yaxis data) –
 plot_type (string from list ["scatter","bar"] of expected plot type) –
 line_types (list of strings. Acceptable strings in line_types are as follows ["regression", "onetoone"]) – if list is empty, assert is passed
 xlabels (boolean if using x axis labels rather than x data) –
 lims_equal (boolean expressing if x and y limits are expected to be equal) –
 title_contains (list of lower case strings where each string is expected to be in title, barring capitalization.) – If value is an empty list: test is just to see that title exists and is not an empty string If value is None: no tests are run
 title_type (one of the following strings ["figure", "axes", "either"]) – “figure”: only the figure title (suptitle) will be tested “axes”: only the axes title (suptitle) will be tested “either”: either the figure title or axes title will pass this assertion. The combined title will be tested.
 xlabel_contains (list of lower case strings where each string is expected to be in xaxis label, barring capitalization.) – If value is an empty list: test is just to see that xaxis label exists and is not an empty string If value is None: no tests are run
 ylabel_contains (list of lower case strings where each string is expected to be in yaxis label, barring capitalization.) – If value is an empty list: test is just to see that yaxis label exists and is not an empty string If value is None: no tests are run
 caption_string (list of lists. Each internal list is a list of lower case strings where at least one string must be) – found in the caption, barring capitalization if empty list: asserts caption exists and not an empty string if None: no tests are run
 legend_labels (list of lower case stings. Each string is an expected entry label in the legend, barring capitalization.) –

cases
¶ Returns a list of TestCases to be run in a TestLoader for basic 2d plots (scatter, bar, line, etc.).
Testcases are as follows: 1. LabelsCase: Asserts the title, xaxis label, and yaxis label are as expected 2. BasicCase: Asserts data matches data_exp, and other assertions based on params listed below For more on tests, see init method above. For more on assertions, see the autograde package.

suite
¶ Returns a Testsuite from cases to be run in a TestRunner

class
matplotcheck.cases.
PlotFoliumSuite
(fmap, markers)[source]¶ Bases:
object
A generic object to test Folium Maps.
Parameters:  fmap (folium map to be tested) –
 markers (set of tuples where each tuple represents the x and y coord of an expected marker) –

cases
¶ Returns a TestSuite for Folium Maps. Testcase are as follows: 1. FoliumCase: asserts map is of type folium.map and contains expected markers

suite
¶ Returns a Testsuite from cases to be run in a TestRunner

class
matplotcheck.cases.
PlotHistogramSuite
(ax, n_bins=None, xlims=None, ylims=None, title_contains=[], xlabel_contains=[], ylabel_contains=[])[source]¶ Bases:
matplotcheck.cases.PlotBasicSuite
A PlotBasicSuite object to test a Matplotlib histogram plot. Since students have the flexibility to determine bin size, we are testing the set up of the histogram more than the data in the histogram itself.
Parameters:  ax (Matplotlib Axes to be tested) –
 n_bins (tuple of ints. First int is the minimum number of bins containing) – negative values. Second int is the minimum number of bins containing positive values
 xlims (tuple of 2 tuples. First tuple contains range the left x limit must) – be in, exclusive. Second tuple contains range the right x limit must be in, exclusive.
 ylims (tuple of 2 tuples. First tuple contains range the bottom y limit) – must be in, exclusive. Second tuple contains range the top y limit must be in, exclusive.
 title_contains (list of lower case strings where each string is expected to) – be in title, barring capitalization. If value is an empty list: test is just to see that title exists and is not an empty string If value is None: asserts no title
 xlabel_contains (list of lower case strings where each string is expected to) – be in xaxis label, barring capitalization. If value is an empty list: test is just to see that xaxis label exists and is not an empty string If value is None: asserts no label is expressed
 ylabel_contains (list of lower case strings where each string is expected) – to be in yaxis label, barring capitalization. If value is an empty list: test is just to see that yaxis label exists and is not an empty string If value is None: asserts no label is expressed

cases
¶ Asserts the title, xaxis label, and yaxis label are as expected 2. HistogramCase: number of negative and positive bins as declares in n_bins. x axis limits and y axis limits are in range declared by xlims and y lims. For more on tests, see init method above. For more on assertions, see the autograde package.
Type: Returns list of cases for a histogram. Testcases are as follows
Type:  LabelsCase

class
matplotcheck.cases.
PlotRasterSuite
(ax, im_expected, caption_strings, im_classified=True, legend_labels=None, title_type='either', title_contains=[], markers=None, markers_by_size=None, markers_groupby=None, lines=None, lines_groupby=None, polygons=None, colorbar_range=None)[source]¶ Bases:
matplotcheck.cases.PlotVectorSuite
A PlotBasicSuite object to test a Matplotlib raster plot.
Parameters:  ax (Matplotlib Axes to be tested) –
 im_expected (array containing values of an expected image) –
 caption_strings (list of lists. Each internal list is a list of strings where at least one string must be) – found in the caption, barring capitalization if empty list: asserts caption exists and not an empty string if None: assertion is passed
 im_classified (boolean if image on ax is classfied) –
 legend_labels (list of lists. Each internal list represents a classification category.) – Said list is a list of strings where at least one string is expected to be in the legend label for this category. Internal lists must be in the same order as bins in im_expected.
 title_type (one of the following strings ["figure", "axes", "either"], stating which title to test) –
 title_contains (list of strings expected to be in title) –
 markers (Geopandas dataframe with geometry column containing expected Point objects) –
 markers_by_size (column title from markers_exp that points are expected to be sorted by) – if None, assertion is passed
 markers_groupby (column title from markers_exp that points are expected to be grouped by/contain) – like attributes. Attributes tested are: marker type, markersize, and color if None, assertion is passed
 lines (Geopandas dataframe with geometry column containing expected LineString and MultiLineString objects) –
 lines_groupby (column title from line_exp that lines are expected to be grouped by/contain) – like attributes. Attributes tested are: line style, line width, and color if None, assertion is passed
 polygons (list of lines where each line is a list of coord tuples for the exterior polygon) –
 colorbar_range (tuple of (min, max) for colorbar.) – If empty tuple: asserts a colorbar exists, but does not check values If None: assertion is passed

cases
¶ Returns a list of TestCases for spatial raster plots. Testcase are as follows: 1. CaptionCase: assert caption is in appropriate location with strings expressed in caption_strings 2. LabelsCase: asserts the title contains strings in title_contains, and x and y labels are empty 3. RasterCase: asserts raster image matches im_expected and legend is correct if image is classified 4. VectorCase: assert vector data is as expected

class
matplotcheck.cases.
PlotTimeSeriesSuite
(ax, data_exp, xcol, ycol, no_data_val=None, major_locator_exp=None, minor_locator_exp=None, title_contains=[], xlabel_contains=[], ylabel_contains=[])[source]¶ Bases:
matplotcheck.cases.PlotBasicSuite
A PlotBasicSuite object to test Matplotlib time series plots.
Parameters:  ax (Matplotlib Axes to be tested) –
 data_exp (pandas dataframe containing plot data) –
 x_col (string column title in data_exp that contains xaxis data) –
 y_col (string column title in data_exp that contains yaxis data) –
 no_data_val (float representing no data, as stated by the input data) –
 major_locator_exp (one of the following ['decade', 'year', 'month', 'week', 'day', None]) – decade: if tick should be shown every ten years year: if tick should be shown every new year month: if tick should be shown every new month week: if tick should be shown every new week day: if tick should be shown every new day
 minor_locator_exp (one of the following ['decade', 'year', 'month', 'week', 'day', None], as expressed above) –
 title_contains (list of lower case strings where each string is expected to be in title, barring capitalization.) – If value is an empty list: test is just to see that title exists and is not an empty string If value is None: asserts no title
 xlabel_contains (list of lower case strings where each string is expected to be in xaxis label, barring capitalization.) – If value is an empty list: test is just to see that xaxis label exists and is not an empty string If value is None: asserts no label is expressed
 ylabel_contains (list of lower case strings where each string is expected to be in yaxis label, barring capitalization.) – If value is an empty list: test is just to see that yaxis label exists and is not an empty string If value is None: asserts no label is expressed

cases
¶ Returns a list of TestCases for time series plots. Testcase are as follows: 1. LabelsCase: Asserts the title, xaxis label, and yaxis label are as expected 2. TickReformatCase: Asserts xaxis ticks have large ticks as express in major_locator_exp and small ticks as express in minor_locator_exp 3. TimeSeriesCase: Asserts data matches data_exp and is converted to time objects For more on tests, see init method above. For more on assertions, see the autograde package.

class
matplotcheck.cases.
PlotVectorSuite
(ax, caption_strings, legend_labels, title_type='either', title_contains=[], markers=None, lines=None, polygons=None, markers_groupby=None, lines_groupby=None, markers_by_size=None)[source]¶ Bases:
matplotcheck.cases.PlotBasicSuite
A PlotBasicSuite object to test a Matplotlib plot with spatial vector data.
Parameters:  ax (Matplotlib Axes to be tested) –
 caption_strings (list of lists. Each internal list is a list of lower case strings where at least one string must be) – found in the caption, barring capitalization if None: assert caption does not exist if empty list: asserts caption exists and not an empty string
 legend_labels (list of lower case stings. Each string is an expected entry label in the legend.) –
 title_type (one of the following strings ["figure", "axes", "either"]) – “figure”: only the figure title (suptitle) will be tested “axes”: only the axes title (suptitle) will be tested “either”: either the figure title or axes title will pass this assertion. The combined title will be tested.
 title_contains (list of lower case strings where each string is expected to be in title, barring capitalization.) – If value is an empty list: test is just to see that title exists and is not an empty string If value is None: asserts no title
 markers (Geopandas dataframe with geometry column containing expected Point objects) –
 lines (Geopandas dataframe with geometry column containing expected LineString and MultiLineString objects) –
 polygons (list of lines where each line is a list of coord tuples for the exterior polygon) –
 markers_groupby (column title from markers_exp that points are expected to be grouped by/contain) – like attributes. Attributes tested are: marker type, markersize, and color if None, assertion is passed
 lines_groupby (column title from line_exp that lines are expected to be grouped by/contain) – like attributes. Attributes tested are: line style, line width, and color if None, assertion is passed
 markers_by_size (column title from markers_exp that points are expected to be sorted by) – if None, assertion is passed

cases
¶ Returns a list of TestCases for spatial vector plots. Testcase are as follows: 1. CaptionCase: assert caption is in appropriate location with strings expressed in caption_contains 2. LabelsCase: asserts the title contains strings in title_contains, and x and y labels are empty 3. LegendCase: assert legend(s) is/are in appropriate location with legend_labels 4. VectorCase: assert vector data is as expected in markers, lines, and polygons For more on tests, see init method above. For more on assertions, see the autograde package.
matplotcheck.folium module¶

class
matplotcheck.folium.
FoliumTester
(fmap)[source]¶ Bases:
object
object to test Folium plots
Parameters: map (folium.folium.Map object) – 
assert_folium_marker_locs
(markers, m='Markers not shown in appropriate location')[source]¶ Asserts folium contains markers with locations described in markers_exp and only those markers, with error message m
Parameters:  markers (set of tuples where each tuple represents the x and y coord of an expected marker) –
 m (string error message if assertion is not met) –

matplotcheck.notebook module¶

matplotcheck.notebook.
convert_axes
(plt, which_axes='current')[source]¶ Saves current working plot and axes as variables for testing purposes. Axes that is/are saved is denoted by which_axes.
Parameters:  plt (Matplotlib plot to be tested) –
 which_axes (string from the following list ['current', 'last', 'first', 'all'] stating which axes we are saving for testing) –
Returns: ax
Return type: Matplotlib axes or list of axes as express by which_axes

matplotcheck.notebook.
error_test
(n, n_exp)[source]¶ Tests the number of cells that produced an error.
Parameters:  n (int of number of cells that that did not produce an error) –
 n_exp (int of number of cell that are checked if producing an error) –
Returns: Return type: print statement of test results

matplotcheck.notebook.
import_test
(var_dict, n)[source]¶ Tests no import statements are found after the first cell in a Jupyter Notebook
Parameters:  vars_dict (dictionary produced by 'locals()' in notebook) –
 n (number of cells to be tested for import statement in Jupyter Notebook) –
Returns: Return type: print statement of test results
matplotcheck.raster module¶

class
matplotcheck.raster.
RasterTester
(ax)[source]¶ Bases:
matplotcheck.base.PlotTester
A PlotTester for spatial raster plots.
Parameters: ax ( `matplotlib.axes.Axes`
object) –
assert_colorbar_range
(crange)[source]¶ Asserts colorbar range matches min and max of crange parameter.
Parameters: crange (tuple of (min, max) for colorbar) – If given empty tuple, asserts exactly 1 colorbar exists, but does not check values. Returns: Return type: Nothing (if checks pass) or raises error

assert_image
(im_expected, im_classified=False, m='Incorrect Image Displayed')[source]¶ Asserts the first image in Axes ax matches array im_expected
Parameters:  im_expected (array containing the expected image data) –
 im_classified (boolean, set to True image has been classified.) – Since classified images values can be reversed or shifted and still produce the same image, setting this to True will allow those changes.
 m (string error message if assertion is not met) –
Returns: Return type: Nothing (if checks pass) or raises error

assert_image_full_screen
(m='Image is stretched inaccurately')[source]¶ Asserts the first image in ax fills the entire axes window
Parameters: m (error message if assertion is not met) – Returns: Return type: Nothing (if checks pass) or raises error with message m

assert_legend_accuracy_classified_image
(im_expected, all_label_options)[source]¶ Asserts legend correctly describes classified image on Axes ax, checking the legend labels and the values
Parameters:  im_expected (array of arrays with expected classified image on ax.) – Class values must start with 0, 1, 2, etc.
 all_label_options (list of lists) – Each internal list represents a class and said list is a list of strings where at least one string is expected to be in the legend label for this category. Internal lists must be in the same order as bins in im_expected, e.g. first internal list has the expected label options for class 0.
Returns: Return type: Nothing (if checks pass) or raises error
Notes
First compares all_label_options against the legend labels to find which element of all_label_options matches that entry. E.g. if the first legend entry has a match in the first list in all_label_options, then that legend entry corresponds to the first class (value 0). Then the plot image array is copied and the values are set to the legend label that match the values (i.e. the element in all_label_options). The same is done for the expected image array. Finally those two arrays of strings are compared. Passes if they match.

matplotcheck.timeseries module¶

class
matplotcheck.timeseries.
TimeSeriesTester
(ax)[source]¶ Bases:
matplotcheck.base.PlotTester
A PlotTester for 2 dimensional time series plots.
Parameters: ax ( `matplotlib.axes.Axes`
object) – The plot to be tested.
assert_no_data_value
(nodata=999.99)[source]¶ Asserts nodata values have been removed from the data, when x is a datetime with error message m
Parameters:  nodata (float or int) – a nodata value that will be searched for in dataset
 xtime (boolean) – does the xaxis contains datetime values?

assert_xdata_date
(x_exp, m='Xaxis is not in appropriate date format')[source]¶ Asserts xaxis data has been parsed into datetime objects. Matplotlib changes datetime to floats representing number of days since day 0. If you are using dates prior to year 270, this assertion will fail.
Parameters: x_exp (expected x_axis values, must be in a datetime format) –

assert_xticks_locs
(tick_size='large', loc_exp=None, m='Incorrect X axis tick locations')[source]¶ Asserts that Axes ax has xaxis ticks as noted by tick_size and loc_exp
Parameters:  tick_size (str, opts: ['large','small']) – ‘large’: if testing large ticks ‘small’: if testing small ticks
 loc_exp (string ['decade','year', 'month', 'week', 'day']) – ‘decade’: if tick should be shown every ten years ‘year’: if tick should be shown every new year ‘month’: if tick should be shown every new month ‘week’: if tick should be shown every new week ‘day’: if tick should be shown every new day None: if no tick location has been specified. This will automatically assert True
 m (error message if assertion is not met) –

assert_xticks_reformatted
(tick_size='large', loc_exp=None, m='x ticks have not been reformatted properly')[source]¶ Asserts that Axes ax xtick have been reformatted as denoted by tick_size and loc_exp, with error message m
Parameters:  tick_size (must be one of the following ['large','small']) – ‘large’: if testing large ticks ‘small’: if testing small ticks
 loc_exp (string ['decade','year', 'month', 'week', 'day']) – ‘decade’: if tick should be shown every ten years ‘year’: if tick should be shown every new year ‘month’: if tick should be shown every new month ‘week’: if tick should be shown every new week ‘day’: if tick should be shown every new day None: if no tick format has been specified. This will automatically assert True
 m (string error message if assertion is not met) –

matplotcheck.vector module¶

class
matplotcheck.vector.
VectorTester
(ax)[source]¶ Bases:
matplotcheck.base.PlotTester
A PlotTester for spatial vector plots.
Parameters: ax ( `matplotlib.axes.Axes`
object) –
assert_collection_sorted_by_markersize
(df_expected, sort_column)[source]¶ Asserts a collection of points vary in size by column expresse din sort_column
Parameters:  df_expected (geopandas dataframe with geometry column of expected point locations) –
 sort_column (column title from df_expected that points are expected to be sorted by) – if None, assertion is passed

assert_legend_no_overlay_content
(m='Legend overlays plot contents')[source]¶ Asserts that each legend does not overlay plot contents with error message m
Parameters: m (string error message if assertion is not met) –

assert_lines
(lines_expected, m='Incorrect Line Data')[source]¶ Asserts the line data in Axes ax is equal to lines_expected with error message m. If line_expected is None or an empty list, assertion is passed
Parameters:  lines_expected (Geopandas Dataframe with a geometry column consisting of MultilineString and LineString objects) –
 m (string error message if assertion is not met) –

assert_lines_grouped_by_type
(lines_expected, sort_column, m='Line attributes not accurate by type')[source]¶ Asserts that the lines on Axes ax display like attributes based on their type with error message m attributes tested are: color, linewidth, linestyle
Parameters:  lines_expected (Geopandas Dataframe with geometry column consisting of MultiLineString and LineString objects) –
 sort_column (string of column title in lines_expected that contains types lines are expected to be grouped by) –
 m (string error message if assertion is not met) –

assert_no_legend_overlap
(m='Legends overlap eachother')[source]¶ 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) –

assert_points_grouped_by_type
(data_exp, sort_column, m='Point attribtues not accurate by type')[source]¶ Asserts that the points on Axes ax display attributes based on their type with error message m attributes tested are: color, marker, and markersize
Parameters:  data_exp (Geopandas Dataframe with Point objects in column 'geometry') – an additional column with title sort_column, denotes a category for each point
 sort_column (string of column label in dataframe data_exp.) – this column contains values expressing which points belong to which group
 m (string error message if assertion is not met) –

assert_polygons
(polygons_expected, dec=None, m='Incorrect Polygon Data')[source]¶ Asserts the polygon data in Axes ax is equal to polygons_expected to decimal place dec with error message m If polygons_expected is am empty list or None, assertion is passed
Parameters:  polygons_expected (list of polygons expected to be founds on Axes ax) –
 dec (int stating the desired decimal precision. If None, polygons must be exact) –
 m (string error message if assertion is not met) –

get_lines
()[source]¶ Returns a dataframe with all lines on ax
Returns:  output (DataFrame with column ‘lines’. Each row represents one line segment.)
 Its value in ‘lines’ is a list of tuples representing the line segement.

get_lines_by_attributes
()[source]¶  Returns a sorted list of lists where each list contains line segments of the same attributes:
 color, linewidth, and linestyle
Returns: Return type: sorted list where each list represents all lines with the same attributes

get_lines_by_collection
()[source]¶ Returns a sorted list of list where each list contains line segments from the same collections
Returns: Return type: sorted list where each list represents all lines from the same collection

get_points_by_attributes
()[source]¶ Returns a sorted list of lists where each list contains tuples of xycoords for points of the same attributes: color, marker, and markersize
Returns:  sorted list where each list represents all points with the same color.
 each point is represented by a tuple with its coordinates.

Module contents¶
Autograde functions for the earthlab class.