# Line plots¶

Inherits from `PlotChecker`.

class `plotchecker.``LinePlotChecker`(axis)[source]

A plot checker for line plots.

Parameters: axis : `matplotlib.axes.Axes` object A set of matplotlib axes (e.g. obtained through `plt.gca()`)
`find_permutation`(attr_name, attr_vals)[source]

Find the order of the lines such that the given attribute (given by `attr_name` and `attr_vals`) has values in the same order as those that were plotted.

This function is useful if you are not sure what order the lines were plotted in. If, for example, you know there should be one red line, one blue line, and one green line—but not the order—you can use this method with `'color'` as the attribute name and ```['red', 'green', 'blue']``` as the attribute values. Then, any subsequent assertions will use the permutation found by this function.

Parameters: attr_name : string The name of the attribute to use for finding the permutation. attr_vals : The expected values of the attribute

Examples

Let’s say the instructions are to create three lines: one red line with data `xr` and `yr`; one blue line with data `xb` and `yb`, and one green line with data `xg` and `yg`. Here is one way that plot might be created:

```fig, ax = plt.subplots()
ax.plot(xg, yg, 'g-')
ax.plot(xb, yb, 'b-')
ax.plot(xr, yr, 'r-')
```

However, the lines could have been plotted in any order. So, for example, the following would fail, because it assumes the order is ‘red’, ‘green’, and ‘blue’:

```pc = LinePlotChecker(ax)
pc.assert_x_data_equal([xr, xg, xb])    # fails
```

To avoid having to check every permutation, you can use this `find_permutation` method to do it for you:

```pc = LinePlotChecker(ax)
pc.find_permutation('color', ['r', 'g', 'b'])
pc.assert_x_data_equal([xr, xg, xb])    # passes
```
`assert_num_lines`(num_lines)[source]

Assert that the plot has the given number of lines.

Parameters: num_lines : int
`x_data`

The x-values of the plotted data (list of arrays, one array per line).

`assert_x_data_equal`(x_data)[source]

Assert that the given x-data is equivalent to the plotted `x_data`.

Parameters: x_data : list of array-like The expected x-data. The number of elements should be equal to the (expected) number of plotted lines.
`assert_x_data_allclose`(x_data, **kwargs)[source]

Assert that the given x-data is almost equal to the plotted `x_data`.

Parameters: x_data : list of array-like The expected x-data. The number of elements should be equal to the (expected) number of plotted lines. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`y_data`

The y-values of the plotted data (list of arrays, one array per line).

`assert_y_data_equal`(y_data)[source]

Assert that the given y-data is equivalent to the plotted `y_data`.

Parameters: y_data : list of array-like The expected y-data. The number of elements should be equal to the (expected) number of plotted lines.
`assert_y_data_allclose`(y_data, **kwargs)[source]

Assert that the given y-data is almost equal to the plotted `y_data`.

Parameters: y_data : list of array-like The expected y-data. The number of elements should be equal to the (expected) number of plotted lines. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`colors`

The colors of the plotted lines. Each color is a RGB 3-tuple.

`assert_colors_equal`(colors)[source]

Assert that the given colors are equivalent to the plotted `colors`.

Parameters: colors : list of expected line colors Each color can be either a matplotlib color name (e.g. `'r'` or `'red'`), a hexcode (e.g. `"#FF0000"`), a 3-tuple RGB color, or a 4-tuple RGBA color.
`assert_colors_allclose`(colors, **kwargs)[source]

Assert that the given colors are almost equal to the plotted `colors`.

Parameters: colors : list of expected line colors Each color can be either a matplotlib color name (e.g. `'r'` or `'red'`), a hexcode (e.g. `"#FF0000"`), a 3-tuple RGB color, or a 4-tuple RGBA color. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`alphas`

The alpha values of the plotted lines.

`assert_alphas_equal`(alphas)[source]

Assert that the given alpha values are equivalent to the plotted `alphas`.

Parameters: alphas : list of floats The expected alpha values, with length equal to the (expected) number of plotted lines.
`assert_alphas_allclose`(alphas, **kwargs)[source]

Assert that the given alpha values are almost equal to the plotted `alphas`.

Parameters: alphas : list of floats The expected alpha values, with length equal to the (expected) number of plotted lines. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`linewidths`

The line widths of the plotted lines.

`assert_linewidths_equal`(linewidths)[source]

Assert that the given line widths are equivalent to the plotted `linewidths`.

Parameters: linewidths : list of numbers The expected linewidths, with length equal to the (expected) number of plotted lines.
`assert_linewidths_allclose`(linewidths, **kwargs)[source]

Assert that the given line widths are almost equal to the plotted `linewidths`.

Parameters: linewidths : list of numbers The expected linewidths, with length equal to the (expected) number of plotted lines. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`markerfacecolors`

The colors of the marker faces for the plotted lines.

`assert_markerfacecolors_equal`(markerfacecolors)[source]

Assert that the given marker face colors are equivalent to the plotted `markerfacecolors`.

Parameters: markerfacecolors : list of expected marker face colors Each color can be either a matplotlib color name (e.g. `'r'` or `'red'`), a hexcode (e.g. `"#FF0000"`), a 3-tuple RGB color, or a 4-tuple RGBA color.
`assert_markerfacecolors_allclose`(markerfacecolors, **kwargs)[source]

Assert that the given marker face colors are almost equal to the plotted `markerfacecolors`.

Parameters: markerfacecolors : list of expected marker face colors Each color can be either a matplotlib color name (e.g. `'r'` or `'red'`), a hexcode (e.g. `"#FF0000"`), a 3-tuple RGB color, or a 4-tuple RGBA color. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`markeredgecolors`

The colors of the marker edges for the plotted lines.

`assert_markeredgecolors_equal`(markeredgecolors)[source]

Assert that the given marker edge colors are equivalent to the plotted `markeredgecolors`.

Parameters: markeredgecolors : list of expected marker edge colors Each color can be either a matplotlib color name (e.g. `'r'` or `'red'`), a hexcode (e.g. `"#FF0000"`), a 3-tuple RGB color, or a 4-tuple RGBA color.
`assert_markeredgecolors_allclose`(markeredgecolors, **kwargs)[source]

Assert that the given marker edge colors are almost equal to the plotted `markeredgecolors`.

Parameters: markeredgecolors : list of expected marker edge colors Each color can be either a matplotlib color name (e.g. `'r'` or `'red'`), a hexcode (e.g. `"#FF0000"`), a 3-tuple RGB color, or a 4-tuple RGBA color. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`markeredgewidths`

The widths of the marker edges for the plotted lines.

`assert_markeredgewidths_equal`(markeredgewidths)[source]

Assert that the given marker edge widths are equivalent to the plotted `markeredgewidths`.

Parameters: markeredgewidths : list of expected marker edge widths The expected edge widths, with length equal to the (expected) number of plotted lines.
`assert_markeredgewidths_allclose`(markeredgewidths, **kwargs)[source]

Assert that the given marker edge widths are almost equal to the plotted `markeredgewidths`.

Parameters: markeredgewidths : list of expected marker edge widths The expected edge widths, with length equal to the (expected) number of plotted lines. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`markersizes`

The marker sizes for the plotted lines.

`assert_markersizes_equal`(markersizes)[source]

Assert that the given marker sizes are equivalent to the plotted `markersizes`.

Parameters: markersizes : list of expected marker sizes The expected marker sizes, with length equal to the (expected) number of plotted lines.
`assert_markersizes_allclose`(markersizes, **kwargs)[source]

Assert that the given marker sizes are almost equal to the plotted `markersizes`.

Parameters: markersizes : list of expected marker sizes The expected marker sizes, with length equal to the (expected) number of plotted lines. kwargs : Additional keyword arguments to pass to `numpy.testing.assert_allclose`
`markers`

The marker types for the plotted lines.

`assert_markers_equal`(markers)[source]

Assert that the given markers are equivalent to the plotted `markers`.

Parameters: markers : list of strings The expected markers, with length equal to the (expected) number of plotted lines.
`labels`

The legend labels of the plotted lines.

`assert_labels_equal`(labels)[source]

Assert that the given legend labels are equivalent to the plotted `labels`.

Parameters: labels : list of strings The expected legend labels, with length equal to the (expected) number of plotted lines.