1-Dimensional plotting functions

src.splotch.plots_1d.axline(x=None, y=None, a=None, b=None, xlim=None, ylim=None, xinvert=False, yinvert=False, xlog=False, ylog=False, title=None, xlabel=None, ylabel=None, label=None, grid=None, ax=None, plot_kw={}, **kwargs)

Generalised axis lines.

This function aims to generalise the usage of axis lines calls (axvline/axhline) together and to allow lines to be specified by a slope/intercept according to the function y=a*x + b.

Parameters
  • x (int or list, optional) – x position(s) in data coordinates for a vertical line(s).

  • y (int or list, optional) – y position(s) in data coordinates for a horizontal line(s).

  • a (int or list, optional) – Slope(s) of diagonal axis line(s), defaults to 1 if not specified when b is given.

  • b (int or list, optional) – Intercept points(s) of diagonal axis line(s), defaults to 0 if not specified when a is given.

  • xlim (tuple-like, optional) – Defines the limits of the x-axis, it must contain two elements (lower and higer limits).

  • ylim (tuple-like, optional) – Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • xinvert (bool or list, optional) – If true inverts the x-axis.

  • yinvert (bool or list, optional) – If true inverts the y-axis.

  • xlog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • ylog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • title (str, optional) – Sets the title of the plot

  • xlabel (str, optional) – Sets the label of the x-axis.

  • ylabel (str, optional) – Sets the label of the y-axis.

  • label (str, optional) – Sets the legend for the plot.

  • grid (boolean, dict or None) –

    The grid behaviour, acts according to:
    • If boolean, the grid is set on (True) or off (False).

    • If dict, allows specific .Line2D properties of the grid to be set.

    • If None, use default grid parameters if this is the initial plotting call, otherwise do nothing.

  • ax (pyplot.Axes or list-like, optional) – Specifies the axes on which to plot the lines, defaults to the current axes.

  • plot_kw (dict, optional) – Passes the given dictionary as a kwarg to the plotting function. Valid kwargs are Line2D properties.

  • **kwargs (Line2D properties, optional) – kwargs are used to specify matplotlib specific properties such as linecolor, linewidth, antialiasing, etc. A list of available Line2D properties can be found here: https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D

Returns

A list of Line2D objects representing the plotted lines. If more than one subplot and/or line is plotted, the resulting list will be multi-dimensional with the dimensions corresponding to the axes/lines.

Return type

lines

src.splotch.plots_1d.brokenplot(x, y=None, xbreak=None, ybreak=None, xlim=None, ylim=None, sep=0.05, overflow=0.05, xinvert=False, yinvert=False, xlog=False, ylog=False, title=None, xlabel=None, ylabel=None, label=None, lab_loc=0, ax=None, grid=None, plot_kw={}, **kwargs)

Broken Axis Plot Function

Creates a standard plot call with an axis break at xbreak or ybreak for vertical or horizontal breaks.

Parameters
  • x (array-like or list) – If list it is assumed that each elemement is array-like. If y is not given, the given values pass to y and a numpy array is generated with numpy.arange() for the x values.

  • y (array-like or list, optional) – If list it is assumed that each elemement is array-like.

  • xbreak/ybreak (float or tuple-like, required) – The location(s) of the vertical or horizontal breaks is controlled by xbreak or ybreak, respectively. The value can be a single location or a tuple defining the (start, stop) points of the break. Only one coordinate can be broken in a given plot.

  • xlim (tuple-like, optional) – Defines the limits of the x-axis, it must contain two elements (lower and higer limits).

  • ylim (tuple-like, optional) – Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • sep (float, optional (default: 0.05)) – The separation size of the axis break, given as a fraction of the axis dimensions.

  • overflow (float, optional (default: 0.05)) – The fractional overflow of the axes beyond the break values. Often good to keep this non-zero as breaking the axis exactly at the break point leaves the final gridlines and ticks out of view.

  • xinvert (bool or list, optional) – If true inverts the x-axis.

  • yinvert (bool or list, optional) – If true inverts the y-axis.

  • xlog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • ylog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • title (str, optional) – Sets the title of the plot

  • xlabel (str, optional) – Sets the label of the x-axis.

  • ylabel (str, optional) – Sets the label of the y-axis.

  • label (str, optional) – Sets the legend for the plot.

  • lab_loc (int, optional) – Defines the position of the legend

  • ax (pyplot.Axes, optional) – Use the given axes to make the plot, defaults to the current axes.

  • grid (boolean, optional) – If not given defaults to the value defined in splotch.Params.

  • plot_kw (dict, optional) – Passes the given dictionary as a kwarg to the plotting function. Valid kwargs are Line2D properties.

  • **kwargs (Line2D properties, optional) – kwargs are used to specify matplotlib specific properties such as linecolor, linewidth, antialiasing, etc. A list of available Line2D properties can be found here: https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D

Returns

  • lines (list of Line2D) – A list of Line2D objects (paired as tuples) representing the plotted data. The lines are given as pairs to correspond to the separate lines either side of the x/ybreak.

  • ax2 (pyplot.Axes, optional) – The additional axis object created.

src.splotch.plots_1d.curve(expr, var=None, subs={}, orientation='horizontal', permute=False, bounds=None, num=101, xlim=None, ylim=None, xinvert=False, yinvert=False, xlog=False, ylog=False, grid=None, title=None, xlabel=None, ylabel=None, label=True, uselatex=True, ax=None, plot_kw={}, **kwargs)

Plot Mathematical Expressions

Plot the curve(s) corresponding to mathematical expressions over a given range across the independent variable. Expressions can be given with multiple variables, whereby one is taken to be the independent variable and all others are substitution variables, which can take a variable number of values producing the corresponding number of curves.

Parameters
  • expr (str, sympy.Expr, callable() or list-like) – An expression parsed either as a string, sympy expression or callable (function or lambda) which will be evaluated by the function in the range of bounds.

  • var (str or sympy symbol, default: ‘x’) – The independent variable on which to evaluate the expression (i.e. the variable on the x-axis). This defaults to the first non-numeric element of the expression or otherwise simply assumes this to be ‘x’ (if orientation=’horizotnal’, else ‘y’).

  • subs (dict, optional) – If expr contains more symbols than the independent variable var, this dictionary will substitute numerical values for all additonal symbols given. subs is required if additional symbols are specified in the expression.

  • permute (bool, optional (default: False)) – If subs contains more than one substitution variable with multiple values, setting permute=True will generate curves for each permutation of values given. For example, splotch.curve(‘a*x^2 + b’,subs = {‘a’=[1,2],’b’=[3,4,5]}) will create six curves.

  • orientation (str, optional (default: ‘horizontal’)) – The orientation of the independent axis, i.e. whether the independent variable is defined along the x-axis (‘horizontal’) or the y-axis (‘vertical’) of the plot. splotch.curve(‘a*x’) is notationally the same as splotch.curve(‘1/a*y’,var=’y’,orientation=’vertical’).

  • bounds (list-like, optional) – The range over which the function will be plotted. If not given, these default to the current bounds of the plot.

  • num (int, optional (default: 101)) – The number of values along the independent variable on which to evaulate expr.

  • xlim (tuple-like, optional) – Defines the limits of the x-axis, it must contain two elements (lower and higer limits).

  • ylim (tuple-like, optional) – Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • xinvert (bool or list, optional) – If true inverts the x-axis.

  • yinvert (bool or list, optional) – If true inverts the y-axis.

  • xlog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • ylog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • grid (boolean, dict or None) –

    The grid behaviour, acts according to:
    • If boolean, the grid is set on (True) or off (False).

    • If dict, allows specific .Line2D properties of the grid to be set.

    • If None, use default grid parameters if this is the initial plotting call, otherwise do nothing.

  • title (str, optional) – Sets the title of the plot

  • xlabel (str, optional) – Sets the label of the x-axis.

  • ylabel (str, optional) – Sets the label of the y-axis.

  • label (bool, str or list-like, optional (default: True)) –

    Sets the label(s) of the curve(s) for the legend. label can be one of:
    • True:

      Creates a label for every curve defined by subs. The label will list all values subs that produced the curve. If a parameter in subs has only one value (i.e. constant amongst all curves), it will not appear in the label.

    • str:

      If a single string is given, only one label will be shown and all curves will be shown as the label handle.

    • list-like (length must equal to number of curves):

      A label given to each curve that is produced.

    • False or None:

      No label will be assigned and a legend will not be shown.

  • uselatex (bool, optional (default: True)) – If label==True, sets whether to use LaTeX when creating the labels for legend.

  • ax (pyplot.Axes, optional) – Use the given axes to make the plot, defaults to the current axes.

  • plot_kw (dict, optional) – Passes the given dictionary as a kwarg to the plotting function. Valid kwargs are Line2D properties. It is recommended that kwargs be parsed implicitly through **kwargs for readability.

  • **kwargs (Line2D properties, optional) – kwargs are used to specify matplotlib specific properties such as linecolor, linewidth, antialiasing, etc. A list of available Line2D properties can be found here: https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D

Returns

  • curves (list of (or single) pyplot.Line2D object(s)) – A list of Line2D objects created for each curved create by subs.

  • expr (Sympy.Expr) – If expr was given as a string, this returns the sympy expression created from sympy.sympify(). Otherwise, simply returns the expr that was given.

src.splotch.plots_1d.curve_piecewise(expr, var=None, subs={}, orientation='horizontal', bounds=None, intervals=[], permute=False, num=101, xlim=None, ylim=None, xinvert=False, yinvert=False, xlog=False, ylog=False, grid=None, title=None, xlabel=None, ylabel=None, label=True, uselatex=True, ax=None, plot_kw={}, **kwargs)

Plot Piecewise Mathematical Expressions

Plot the curve(s) corresponding to mathematical expressions over a given range across the independent variable. Expressions can be given with multiple variables, whereby one is taken to be the independent variable and all others are substitution variables. This function can only accept one value per substitution variable.

Parameters
  • expr (str, sympy.Expr, callable() or list-like) – An expression parsed either as a string, sympy expression or callable (function or lambda) which will be evaluated by the function in the range of bounds. A piece-wise function is defined by parsing a list of expressions. The piece-wise functionality must also be reflected in bounds.

  • var (str or sympy symbol, required.) – The independent variable on which to evaluate the expression (i.e. the variable on the x-axis).

  • subs (dict, optional) – If expr contains more symbols than the independent variable var, this dictionary will substitute numerical values for all additonal symbols given. subs is required if additional symbols are specified in the expression.

  • orientation (str, optional (default: ‘horizontal’)) – The orientation of the independent axis, i.e. whether the independent variable is defined along the x-axis (‘horizontal’) or the y-axis (‘vertical’) of the plot. splotch.curve(‘a*x’) is notationally the same as splotch.curve(‘1/a*y’,var=’y’,orientation=’vertical’).

  • bounds (list-like, optional) – The range over which the function will be plotted. If not given, these default to the current bounds of the axes being plotted onto, given by ax.

  • intervals (list-like, required) – The points at which the curve partitions each of the N expressions given in expr. The values must lie lie within bounds as these are assumed to be the minimum and maximum points of the intervals.

  • num (int, optional (default: 101)) – The number of values along the independent variable on which to evaulate expr.

  • xlim (tuple-like, optional) – Defines the limits of the x-axis, it must contain two elements (lower and higer limits).

  • ylim (tuple-like, optional) – Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • xinvert (bool or list, optional) – If true inverts the x-axis.

  • yinvert (bool or list, optional) – If true inverts the y-axis.

  • xlog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • ylog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • grid (boolean, dict or None) –

    The grid behaviour, acts according to:
    • If boolean, the grid is set on (True) or off (False).

    • If dict, allows specific .Line2D properties of the grid to be set.

    • If None, use default grid parameters if this is the initial plotting call, otherwise do nothing.

  • title (str, optional) – Sets the title of the plot

  • xlabel (str, optional) – Sets the label of the x-axis.

  • ylabel (str, optional) – Sets the label of the y-axis.

  • label (bool, str or list-like, optional (default: True)) –

    Sets the label(s) of the curve(s) for the legend. label can be one of:
    • True:

      Creates a label for every curve defined by subs. The label will list all values subs that produced the curve. If a parameter in subs has only one value (i.e. constant amongst all curves), it will not appear in the label.

    • str:

      If a single string is given, only one label will be shown and all curves will be shown as the label handle.

    • list-like (length must equal to number of curves):

      A label given to each curve that is produced.

    • False or None:

      No label will be assigned and a legend will not be shown.

  • uselatex (bool, optional (default: True)) – If label==True, sets whether to use LaTeX when creating the labels for legend.

  • ax (pyplot.Axes, optional) – Use the given axes to make the plot, defaults to the current axes.

  • plot_kw (dict, optional) – Passes the given dictionary as a kwarg to the plotting function. Valid kwargs are Line2D properties. It is recommended that kwargs be parsed implicitly through **kwargs for readability.

  • **kwargs (Line2D properties, optional) – kwargs are used to specify matplotlib specific properties such as linecolor, linewidth, antialiasing, etc. A list of available Line2D properties can be found here: https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D

Returns

  • curves (list of (or single) pyplot.Line2D object(s)) – A list of Line2D objects created for each curved create by subs.

  • expr (Sympy.Expr) – If expr was given as a string, this returns the sympy expression created from sympy.sympify(). Otherwise, simply returns the expr that was given.

src.splotch.plots_1d.hist(data, bin_type=None, bins=None, dens=True, cumul=None, scale=None, weights=None, hist_type=None, orientation='vertical', v=None, vstat=None, nmin=0, color=None, xlim=None, ylim=None, xinvert=False, yinvert=False, xlog=False, ylog=None, title=None, xlabel=None, ylabel=None, label=None, lab_loc=0, ax=None, grid=None, plot_kw={}, output=None, **kwargs)

1D histogram function.

The plotting is done with pyplot.plot(), so histograms are shown with interpolated curves instead of the more common stepwise curve. For this reason splotch.histstep is a better choice for small datasets.

Parameters
  • data (array-like or list) – If list it is assumed that each elemement is array-like.

  • bin_type ({‘number’,’width’,’edges’,’equal’}, optional) – Defines how is understood the value given in bins: ‘number’ for the desired number of bins, ‘width’ for the width of the bins, ‘edges’ for the edges of bins, and ‘equal’ for making bins with equal number of elements (or as close as possible). If not given it is inferred from the data type of bins: ‘number’ if int, ‘width’ if float and ‘edges’if ndarray.

  • bins (int, float, array-like or list, optional) – Gives the values for the bins, according to bin_type.

  • dens (bool or list, optional) – If false the histogram returns raw counts.

  • cumul (bool or list, optional) – If true, produces a cumulative distribution instead of a histogram.

  • scale (float or list, optional) – Scaling to be applied to the counts.

  • weights (array-like or None, optional) – An array of weights with the same shape as data. For each value in data, it will only contribute its given weight towards the bin count (instead of 1). If dens is True, weights will also be normalised so that the integral over the density remains 1. Default: None

  • hist_type (str, optional.) – Defines the type of histogram to be drawn. ‘line’ and ‘step’ produce lines, with the former drawing lines conecting the values of each bin positioned on their centre, and the latter drawing a stepwise line, with the edges of each step coinciding with the bin edges. ‘bar’ produces a bar plot. All have filled version (i.e., ‘linefilled’), which fills the space between the edges of the histogram and 0.

  • orientation ({‘vertical’, ‘horizontal’}, optional (default: ‘vertical’)) – If ‘horizontal’, histograms values will be plot along the x-axis instead of the default behaviour of plotting in the y-axis.

  • v (array-like or list, optional) – If a valid argument is given in vstat, defines the value used for the binned statistics.

  • vstat (str, function or list, optional) – Must be or contain one of the valid str arguments for the statistics variable in scipy.stats.binned_statistic (‘mean’, ‘median’, ‘count’, ‘sum’, ‘min’ or ‘max’) or function(s) that takes a 1D array and outputs an integer or float.

  • nmin (int, optional (default: 0)) – The minimum number of points required in a bin in order to be plotted.

  • color (color or list-like of colors or None, default: None) – A color or sequence of strings to assign to each dataset given in data. If hist_type is ‘bar’ or any ‘filled’ variant, then color refers to the facecolor, whereas if hist_type is ‘step’, then color refers to the edgecolor. Note that color will be overwritten if facecolor or edgecolor are also specified. Only color is relevant when hist_type = ‘line’. If None given, uses the next color in the current color cycler.

  • xlim (tuple-like, optional) – Defines the limits of the x-axis, it must contain two elements (lower and higer limits).

  • ylim (tuple-like, optional) – Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • xinvert (bool or list, optional) – If true inverts the x-axis. Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • yinvert (bool or list, optional) – If true inverts the y-axis.

  • xlog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • ylog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • title (str, optional) – Sets the title of the plot

  • xlabel (str, optional) – Sets the label of the x-axis.

  • ylabel (str, optional) – Sets the label of the y-axis.

  • label (str, optional) – Sets the label for the plot.

  • lab_loc (int, optional) – Defines the position of the legend

  • ax (pyplot.Axes, optional) – Use the given axes to make the plot, defaults to the current axes.

  • grid (boolean, dict or None) –

    The grid behaviour, acts according to:
    • If boolean, the grid is set on (True) or off (False).

    • If dict, allows specific .Line2D properties of the grid to be set.

    • If None, use default grid parameters if this is the initial plotting call, otherwise do nothing.

  • plot_par (dict, optional) – Passes the given dictionary as a kwarg to the plotting function.

  • output (boolean, optional) – If True, returns the values and edges of the resulting histogram.

Returns

  • n (list) – List containing the arrays with the values for each histogram drawn. Only provided if output is True.

  • bins_edges (list) – List containing the arrays with the bin edges for each of the histograms drawn. Only provided if output is True.

src.splotch.plots_1d.plot(x, y=None, xlim=None, ylim=None, xinvert=False, yinvert=False, xlog=False, ylog=False, title=None, xlabel=None, ylabel=None, label=None, lab_loc=0, ax=None, grid=None, plot_kw={}, **kwargs)

Base plotting function.

This is a wrapper for pyplot.plot().

Parameters
  • x (array-like or list) – If list it is assumed that each elemement is array-like. If y is not given, the given values pass to y and a numpy array is generated with numpy.arange() for the x values.

  • y (array-like or list, optional) – If list it is assumed that each elemement is array-like.

  • xlim (tuple-like, optional) – Defines the limits of the x-axis, it must contain two elements (lower and higer limits).

  • ylim (tuple-like, optional) – Defines the limits of the y-axis, it must contain two elements (lower and higer limits).

  • xinvert (bool or list, optional) – If true inverts the x-axis.

  • yinvert (bool or list, optional) – If true inverts the y-axis.

  • xlog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • ylog (bool or list, optional) – If True the scale of the x-axis is logarithmic.

  • title (str, optional) – Sets the title of the plot

  • xlabel (str, optional) – Sets the label of the x-axis.

  • ylabel (str, optional) – Sets the label of the y-axis.

  • label (str, optional) – Sets the legend for the plot.

  • lab_loc (int, optional) – Defines the position of the legend

  • ax (pyplot.Axes, optional) – Use the given axes to make the plot, defaults to the current axes.

  • grid (boolean, dict or None) –

    The grid behaviour, acts according to:
    • If boolean, the grid is set on (True) or off (False).

    • If dict, allows specific .Line2D properties of the grid to be set.

    • If None, use default grid parameters if this is the initial plotting call, otherwise do nothing.

  • plot_kw (dict, optional) – Passes the given dictionary as a kwarg to the plotting function. Valid kwargs are Line2D properties.

  • **kwargs (Line2D properties, optional) – kwargs are used to specify matplotlib specific properties such as linecolor, linewidth, antialiasing, etc. A list of available Line2D properties can be found here: https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D

Returns

A list of Line2D objects representing the plotted data.

Return type

lines