matplotcheck package¶
Submodules¶
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 of strings) – Strings to be searched for in axis label. If lst is an empty list: assert axis label exists If lst is None: passes
Returns: Return type: Nothing (if checks pass) or raises error

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: Return type: Nothing (if checks pass) or raises error with message m
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. Once a string is found, it is removed from the caption, therefore, order does matter. This is to enforce no overlap in found strings.
Parameters: strings_exp (list of lists.) – Each internal list is a list of strings where at least one string must be found in the caption. Input strings must be lower case, as we are not testing for capitalization if None: assert caption does not exist if empty list: asserts caption exists and not an empty string

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: Return type: Nothing (if checks pass) or raises error with message m

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: Return type: Nothing (if checks pass) or prints error message 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: Return type: Nothing (if checks pass) or prints error message m

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 checks pass) or prints error message or AssertionError if
 the expected legend title is not found in the object
 or nothing if the title string is found.

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 (flt 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: Return type: Nothing (if checks pass) or raises error

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: Return type: Nothing (if checks pass) or raises error

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 y intercept intercept_exp and goes at least from x coordinate min_val to x coordinate max_val
Parameters:  slope_exp (expected slope of line) –
 intercept_exp (expeted y intercept of line) –
 xtime (boolean if xaxis values are datetime) –
 m (error message if line does not exist) –
 m2 (error message if line exist but does not cover data set) –

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']) – if list is empty, assert 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 error message if assertion is not met) – Returns: Return type: Nothing (if checks pass) or prints error message m

assert_num_bins
(n=3, which_bins='positive')[source]¶ Asserts number of bins of type which_bins is at least n
Parameters:  n (int declaring minimum number of bins of type which_bin) –
 which_bins (string from list ['negative', 'positive']) – ‘negative’: all bins with values centered at a positive value ‘positite’: all bins with values centered at a negative value

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

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.

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 with error message m. Note, this is only testing the numbers in x axis labels.
Parameters:  xy_expected (pandas dataframe that contains data) –
 xcol (string column title containing xaxis data) –
 ycol (string column title containing yaxis data) –
 m (string error message if assertion is not met) –

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 is None, assertion is passed
Parameters:  ax (Matplotlib Axes object (Required)) – Axis object to be tested
 xy_expected (pandas or geopandas dataframe (Required)) – DF 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,) – True if checking only points, false if checking all data on plot
 xtime (boolean) – 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) – if using x axis labels rather than x data
 tolerence (measure of relative error allowed.) – For example, a value of .001 asserts values in array are within .001 of each other. ## this isn’t exactly correct.. ##
 m (string) – error message provided to the student if assertion fails
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: Return type: matplotlib.text.Text if text is found in bottom right. None if no text is found in said location.

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

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

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 none, this is an empty string
 title (title on the axes. If none, this is an empty string.)

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 Ax object) – axes object to be tested
 points_only (boolean) –
 xtime (boolean) – True if the x axis of the plot contains datetime values
Returns: Return type: Pandas dataframe with columns “x” and “y” containing the x and y coords of each point on Axes ax

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 (2x2 array, bounding box of window extents) –
 b2 (2x2 array, bounding box of window extents) –
Returns: Return type: boolean value that says if bounding boxes b1 and b2 overlap

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.