Axis functions

src.splotch.axis_func.adjust_text(which=['x', 'y'], ax=None, text_kw={}, **kwargs)

Adjusts text instances.

Function which allows the user to adjust texts of one or many of either x/y-axis labels, title, legend, colorbars, etc.

Parameters
  • which (str, array-like or list) – Which Text instance(s) to apply the text properties to. Valid arguments can be one or many of the following:

    Arguments

    Description

    ‘x’, ‘xlabel’

    x-axis label

    ‘y’, ‘ylabel’

    y-axis label

    ‘k’, ‘tick’

    Tick labels

    ‘t’, ‘title’

    Title

    ‘s’, ‘suptitle’

    Sup. title

    ‘l’, ‘legend’

    Legend text

    ‘L’, ‘legend title’

    Legend title

    ‘c’, ‘colorbar’

    Color bar

    ‘T’, ‘text’

    Text objects

    ‘a’, ‘all’

    All instances of all the above

    Or a Text object can be specified.

  • ax (pyplot.Axes or list, optional) – Use the given axes to adjust text, defaults to the current axis. If a list of Axis instances given, the text properties is applied to each.

  • text_kw (dict, optional) – Explicit dictionary of kwargs to be parsed to matplotlib Text instance. It is recommended that text keyword arguments be given as **kwargs.

  • **kwargs (Text instance properties) – kwargs are used to specify properties of Text instances. A list of valid Text kwargs can be found in the matplotlib Text documentation.

src.splotch.axis_func.cornerplot(data, columns=None, pair_type='contour', nsamples=None, sample_type='rand', labels=None, histlabel=None, fig=None, figsize=None, wspace=0.0, hspace=0.0, squeeze=False, hist_kw={}, contour_kw={}, scatter_kw={}, hist2D_kw={}, axes_kw={}, _debug_=False, **kwargs)

Creates a corner plot figure and subplots

This function accepts columns of data representing multiple parameters in which each combination will be paired will each other to form the off-diagonals of a corner plot. The diagonals show a 1D histogram representation of each individual parameter.

Parameters
  • data (array-like) – The input data frame with each parameter represented by an individual column, the zeroth axis should be the list of samples and the next axis should be the number of dimensions. Accepted data types are: pandas.DataFrame, pandas.Series, numpy.ndarray, astropy.table.Table.

  • columns (array-like) – The column labels (or indices) that specify which columns within ‘data’ to use. if none specified, every column in ‘data’ with a numeric datatype will be used. To group columns together, columns can be given as a list of lists, e.g.:

    columns=[[‘A1’, ‘A2’, …], [‘B1’, ‘B2’, …]]

    which will create pairs for all parameters in each sublist. Having multiple groups will result in multiple histograms and paired plots per axis. As such, pair_type=’hist2D’ is not compatible when columns includes multiple groups.

  • pair_type (str, optional) – The plotting type for the off-diagonal plots, can be one of:’contour’ | ‘scatter’ | ‘hist2D’ which correspond to contour plots, scatter plots and 2D histograms. A dictionary of parameters can be parsed to one of contour_kw | scatter_kw | hist2D_kw to control the styling of each.

  • nsamples (float, optional) – Specifies the number of samples kept out of the total number of samples. This is useful to speed up plotting if not all of the samples need to be shown. Default: 1 (i.e. no subsampling). Default: the full number samples in data.

  • sample_type (str, optional, Default=’end’) –

    Sets the method used to thin the full set of samples, can be one of the following:
    • ‘end’ : Takes the last nsamples samples (Useful for MCMC posteriors where the end is often better).

    • ‘rand’ : Randomly selects a set of samples. (Only use if confident all posterior chains are stationary).

    • ‘thin’ : Evenly select every m samples until a total of nsamples are kept.

  • labels (array-like (str), optional) – A list of axis labels to be assigned to each parameter. Must be of the same length or longer than the number of columns (or column groups).

  • histlabel (str, optional) – The y-axis label for each of the 1D histograms on the diagonal, if None given, then no labels or ticks will be drawn. Labels and ticks will be displayed on the opposite side to the labels for the pair plots, Default: None.

  • figsize (2-tuple of floats, default: rcParams[“figure.figsize”] * (len(data), len(data))) – The dimensions of the figure (width, height) in inches. If not specified, the default is to scale the default rcParams figure.figsize by the number of rows or columns.

  • wspace / hspace (float, optional) – The horzontal/vertical spacing between figure subplots, expressed as a fraction of the subplot width/height.

  • squeeze (bool, optional, default: True) –

    As per matplotlib’s usage, the following applies:
    • If True, extra dimensions are squeezed out from the returned array of Axes: For NxN, subplots with N>1 are returned as a 2D array or as

    a scalar otherwise. 2D arrays fill out subplots from top-to-bottom and left-to-right. * If False (Default), no squeezing at all is done: the returned Axes object is always a 2D array containing Axes instances, even if it ends up being 1x1. For cornerplots with only one set of diagonals, empty axes will be filled by None.

  • contour_kw, scatter_kw, hist2D_kw (dict, optional) – Dictionary of keyword arguments to be parsed into the pair plotting functions. The particular keyword dictionary used is dependent on the ‘pair_type’ chosen. If ‘columns’ contains multiple groups, kw arguments in lists are assumed to correspond to each group.

  • hist_kw (dict, optional) – Dictionary of keyword arguments to be parsed into the 1D histograms plots on the diagonals.

  • **kwargs (Subplot instance properties) – kwargs are used to specify properties of subplots instances A list of valid axis kwargs can be found here: [https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes](https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes “Matplotlib.axes.Axes”)

src.splotch.axis_func.subplots(naxes=None, nrows=None, ncols=None, va='top', ha='left', wspace=None, hspace=None, widths=None, heights=None, sharex='none', sharey='none', squeeze=True, figsize=None, axes_kw={}, **kwargs)

Adds a set of subplots to figure This is a more-generalised wrapper around matplotlib.pyplot.subplot function to allow for irregularly divided grids.

Parameters
  • naxes (int, optional, default=1) – The number of axes to create. The resulting grid layout created when specifying naxes is decided based on whether ncols and nrows are specified. If:

    • ncols and/or nrows given:

      Makes sure that naxes can be correctly mapped into the specified grid. If one of nrows or ncols not given, the smallest possible grid will be made.

    • both ncols and nrows are None:

      Decides the best possible grid for this number of axes. Currently, this decision is hard-coded with plans for it to become an automatic decision later.

  • nrows, ncols (int, optional) – Number of rows/columns of the subplot grid.

  • va, ha (str, optional, default: ‘top’, ‘left’) – The vertical alignment (va) and horizontal alignment (ha) sets the alignment of grids in the vertical and horizontal directions. Options for va are ‘top’, ‘bottom’ or ‘centre’ and options for ha are ‘left’, ‘right’ and ‘centre’.

  • wspace, hspace (float, optional) – The horzontal/vertical spacing between figure subplots, expressed as a fraction of the subplot width/height.

  • width, heights (array-like, optional) – The width/height ratios of the subplot columns/rows expressed as an array of length ncols/nrows.

  • sharex, sharey (bool or {‘none’, ‘all’, ‘row’, ‘col’}, default: False) – As per matplotlib’s usage, controls sharing of properties among x (sharex) or y (sharey) axes:

    • True or ‘all’: x-/y-axis will be shared among all subplots.

    • False or ‘none’: each subplot x-/y-axis will be independent (default).

    • ‘row’: each subplot row will share an x-/y-axis

    • ‘col’: each subplot column will share an x-/y-axis

    When subplots have a shared x-axis along a column, only the x tick labels of the last complete row of the subplot are created. Similarly, when subplots have a shared y-axis along a row, only the y tick labels of the first complete column subplot are created. To later turn other subplots’ ticklabels on, use ~matplotlib.axes.Axes.tick_params.

  • squeeze (bool, optional, default: True) –

    As per matplotlib’s usage, the following applies:
    • If True, extra dimensions are squeezed out from the returned array of Axes:
      • if only one subplot is constructed (nrows=ncols=1), the resulting single Axes object is returned as a scalar.

      • for Nx1 or 1xM subplots, the returned object is a 1D numpy object array of Axes objects.

      • for NxM, subplots with N>1 and M>1 are returned as a 2D array.

    • If False, no squeezing at all is done: the returned Axes object is always a 2D array containing Axes instances, even if it ends up being 1x1.

    If naxes < ncols*nrows, the only sensible option is to return a 1D numpy array

  • figsize (2-tuple of floats, default: rcParams[“figure.figsize”] * (ncols, nrows)) – The dimensions of the figure (width, height) in inches. If not specified, the default is to scale the default rcParams figure.figsize by the number of rows or columns.

  • axes_kw (dict, optional) – Explicit dictionary of kwargs to be parsed to matplotlib subplot function.

  • **kwargs (Subplot instance properties) – kwargs are used to specify properties of subplots instances A list of valid axis kwargs can be found here: [https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes](https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes “Matplotlib.axes.Axes”)

Returns

  • fig (pyplot.Figure)

  • axes (pyplot.axes.Axes object or array of Axes objects) – axes may either be a single Axes object or a numpy array if naxes > 1. The dimensions of this array are controlled by the squeeze keyword above.