splotch base functions

src.splotch.base_func.axes_handler(new_axis)

New axis handler

Base-level function used by most other plotting functions to set the current Axes instance to ax and returns the old Axes instance to be later reverted.

Parameters

new_axis (Axes object) – The new Axes instance to be set as the current axis.

Returns

curr_axis – The previous Axes instance.

Return type

Axes object

src.splotch.base_func.basehist2D(x, y, c, weights, mbin_type, bin_num, norm, dens, cstat, xlog, ylog)

2D histogram base calculation

Base-level function used by plots_2d.hist2D() and plots_2d.sigma_cont() to calculate the underlying histogram.

Parameters
  • x (ndarray) – Position of data points in the x axis.

  • y (ndarray) – Position of data points in the y axis.

  • c (ndarray) – If a valid argument is given in cstat, defines the value used for the binned statistics.

  • bin_type ({‘number’,’width’,’edges’,’equal’}) – Defines how is understood the value given in bins: ‘number’ for givinf 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.

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

  • norm (float) – Normalization of the counts.

  • dens (bool) – If false the histogram returns raw counts.

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

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

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

Returns

  • x_bins_plot (ndarray) – The bin edges on the x-axis.

  • y_bins_plot (ndarray) – The bin edges on the y-axis.

  • Z (ndarray) – The value of each bin.

src.splotch.base_func.bin_axis(data, btype, bins, log=False, plot_centre=False)

Bin construction for histograms

Base-level function used by all histogram-related functions to construct the bins.

Parameters
  • data (ndarray) – Data to be binned.

  • bin_type ({‘number’,’width’,’edges’,’equal’}) – Defines how is understood the value given in bins: ‘number’ for givinf 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) – Gives the values for the bins, according to bin_type.

  • log (bool, optional) – If True, the bins are constructed in logarithmic space and the logarithm of the data is returned.

  • step (bool, optional) – If True, returns the edges of the bins, instead of the midpoint values.

Returns

  • data (ndarray) – The data for the histogram.

  • hist_bins (ndarray) – The bin edges.

  • plot_bins (ndarray) – The bin centers.

src.splotch.base_func.dict_splicer(plot_dict, Ld, Lx)

Dictionary constructor for plotting

Base-level function used by most other plotting functions to construct a list of dictionaries, each containing the passed arguments to the underlying plotting calls for each different dataset.

Parameters
  • plot_dict (dict) – Contains the parameters to be passed to the underlying plotting function.

  • Ld (int) – Number of plots to be made.

  • Lx (list) – Contains the lenght of the data array of each plot to be made.

Returns

dict_list – List of dictionaries, one for each plot to be made.

Return type

list

src.splotch.base_func.grid_handler(grid, ax=None)

Handles grid behaviour

Base-level function to handle the behaviour of inputs to the grid parameter. If grid is a boolean, then nothing is changed, however, if grid is None, first check whether this is the first plot call to this axis, if so, use rcParams, otherwise do nothing.

Parameters
  • grid (boolean, dict or None) –

    The requested grid settings.
    • If boolean, then the grid is set on (True) or off (False).

    • If dict, then parameters in grid will be parsed into the plt.grid() function.

    • If None and this is the initial plotting call, set to rcParams, else do nothing.

  • ax (Axes object or None) – The axis in which to check the current grid settings.

Returns

gridpar – Returns the modified grid parameters as a dictionary.

Return type

boolean

src.splotch.base_func.is_number(var)

Base-level numeric classificator of variables

Determine whether the argument is a literal number. Booleans, unsigned integers, signed integers, floats and complex numbers are considered numbers. Arrays and list-like objects will return False even if their data type is numeric in kind.

Parameters

array (array-like) – The array to check.

Returns

  • is_numeric (bool) – True if the array has a numeric datatype, False if not.

  • Credit for code (StackExchange users Gareth Rees and MSeifert.)

  • https (//codereview.stackexchange.com/questions/128032/check-if-a-numpy-array-contains-numerical-data)

src.splotch.base_func.is_numeric(array)

Base-level numeric classificator of arrays

Determine whether the argument has a numeric datatype, when converted to a NumPy array. Booleans, unsigned integers, signed integers, floats and complex numbers are the kinds of numeric datatype.

Parameters

array (array-like) – The array to check.

Returns

  • is_numeric (bool) – True if the array has a numeric datatype, False if not.

  • Credit for code (StackExchange users Gareth Rees and MSeifert.)

  • https (//codereview.stackexchange.com/questions/128032/check-if-a-numpy-array-contains-numerical-data)

src.splotch.base_func.lims_handler(lims, ax=None)

Handles xlim/ylim behaviour

Base-level function to handle the behaviour of inputs to the xlim/ylim parameters. If xlim/ylim is a valid tuple, then set these as the limits. However, if xlim/ylim is None, first check whether this is the first plot call to this axis, if so, set to ‘auto’ (i.e. autoscale), otherwise do nothing.

Parameters
  • lims (tuple, str or None) –

    The requested values for xlim/ylim.
    • If tuple, then return these values (if valid).

    • If None and this is the initial plotting call, set to ‘auto’, else set to None

    • If str, must be of the value ‘auto’ return.

  • ax (Axes object or None) – The axis in which to check the current grid settings.

Returns

limspar – Returns the modified grid parameters as a dictionary.

Return type

boolean

src.splotch.base_func.percent_finder(data, p)

Level finder for percentage contours

This function is a base-level function used by plots_2d.sigma_cont to define the level which contains the requested percentage of the data points.

Parameters
  • data (ndarray) – Describes the n-dimensional position of each data point.

  • p (float) – Fraction of the data points to be encircled by the contour.

Returns

min_value – Level for the contour.

Return type

float

src.splotch.base_func.plot_finalizer(xlog, ylog, xlim, ylim, title, xlabel, ylabel, xinvert, yinvert, grid_control)

New axis handler

This function is a base-level function used by most other plotting functions to set the current Axes instance to ax and returns the old Axes instance to be later reverted.

Parameters
  • xlog (None or bool) – If True, the x-axis scale is set to ‘log’.

  • ylog (None or bool) – If True, the y-axis scale is set to ‘log’.

  • xlim (None or array-like) – If given, defines the low and high limits for the x-axis. The first two elements must be int and/or float.

  • ylim (None or array-like) – If given, defines the low and high limits for the y-axis. The first two elements must be int and/or float.

  • title (None or str) – If given, defines the title of the figure.

  • xlabel (None or str) – If given, defines the label of the x-axis.

  • ylabel (None or str) – If given, defines the label of the y-axis.

  • xinvert (None or bool) – If True, ensures the x-axis is inverted. If False, ensures the x-axis is not inverted.

  • yinvert (None or bool) – If True, ensures the y-axis is inverted. If False, ensures the y-axis is not inverted.

  • grid_control (None or bool) – If True, ensures the grid is turned on. If False, ensures the grid is turned off.

Return type

None

src.splotch.base_func.simpler_dict_splicer(plot_dict, Ld, Lx)

Simpler dictionary constructor specifically for plots_1d.curve() plotting

Base-level function used to construct a list of dictionaries for the characters in the expressions to be replaced with numerical values in plots_1d.curve().

Parameters
  • plot_dict (dict) – Contains the parameters to be passed to the underlying plotting function.

  • Ld (int) – Number of plots to be made.

  • Lx (list) – Contains the length of the data array of each plot to be made.

Returns

dict_list – List of dictionaries, one for each plot to be made.

Return type

list

src.splotch.base_func.step_filler(x, y, **kwargs)

Wrapper for a specific fill_between plot.

Parameters
  • x (array-like) – The x-axis values.

  • y (array-like) – The y-axis values.

  • Other arguments (**kwargs) – Optional kwargs supported by fill_between. Note that it will conflict if ‘step’ is given.

Returns

val

Return type

Recasted value

src.splotch.base_func.step_fillerx(x, y, **kwargs)

Wrapper for a specific fill_between plot.

Parameters
  • x (array-like) – The x-axis values.

  • y (array-like) – The y-axis values.

  • Other arguments (**kwargs) – Optional kwargs supported by fill_betweenx. Note that it will conflict if ‘step’ is given.

Returns

val

Return type

Recasted value

src.splotch.base_func.val_checker(val)

Type check of variable to pass to style functions.

Parameters

val (str) – String containing the value to evaluate

Returns

val

Return type

Recasted value