ParrayPlotter

ParrayPlotter(x, y[, z, stdzr, x_scale, ...])

Wrapper for a matplotlib.pyplot function; adjusts ticks and labels according to plotter settings.

Methods

ParrayPlotter.colorbar([mappable, cax, ax])

Wrapper for matplotlib.pyplot.colorbar; adjusts ticks and labels according to plotter settings.

ParrayPlotter.plot([ci, ax, palette, ...])

param ci:

Confidence interval on \(0<\mathtt{ci}<1\). If None, no confidence intervals will be drawn.

ParrayPlotter.plot_ci([ci, ci_style, center, ax])

Plots the confidence interval for an UncertainParameterArray.

ParrayPlotter.update()

Attributes

ParrayPlotter.stdzr

ParrayPlotter.x_scale

ParrayPlotter.x_tick_scale

ParrayPlotter.y_scale

ParrayPlotter.y_tick_scale

ParrayPlotter.z

ParrayPlotter.z_scale

ParrayPlotter.z_tick_scale

ParrayPlotter.x

ParrayPlotter.y

class gumbi.plotting.ParrayPlotter(x: ParameterArray | LayeredArray | np.ndarray, y: UncertainParameterArray | UncertainArray | ParameterArray | LayeredArray | np.ndarray, z: UncertainParameterArray | UncertainArray | ParameterArray | LayeredArray | np.ndarray = None, stdzr: Standardizer = None, x_scale: str = 'natural', x_tick_scale: str = 'natural', y_scale: str = 'natural', y_tick_scale: str = 'natural', z_scale: str = 'natural', z_tick_scale: str = 'natural')

Bases: object

Wrapper for a matplotlib.pyplot function; adjusts ticks and labels according to plotter settings.

Provides a consistent interface to matplotlib plotting functions that allows easy iteration between permutations of plotting and tick labeling in natural, transformed, standardized space. When called on a plotting function, a ParrayPlotter instance passes pre-formated x and y (and z) arrays to the function as positional arguments, along with any additional keyword arguments supplied. ParrayPlotter then adjusts tick labels according to its *_tick_scale arguments.

Passing a .t or .z child of a parray automatically overrides the respective _scale argument. This is achieved by inspecting the variable name for a '_t' or '_z' suffix, so avoiding using variable names with those suffixes to avoid confusion. Note that not all permutations of *_scale and *_tick_scale are permitted: _tick_scale should generally either match the respective _scale argument or be 'natural'.

ParrayPlotter also provides a colorbar() method that adds a colorbar and reformats its ticks and labels according to the z_scale and z_tick_scale attributes.

Parameters:
  • x_pa (ParameterArray | LayeredArray | np.ndarray) – X and Y arrays. If z_pa or stdzr are not supplied, x_pa or y_pa must contain a Standardizer instance.

  • y_pa (ParameterArray | LayeredArray | np.ndarray) – X and Y arrays. If z_pa or stdzr are not supplied, x_pa or y_pa must contain a Standardizer instance.

  • z_pa (ParameterArray | LayeredArray | np.ndarray, optional) – Z array for 2D plots. If stdzr is not supplied, z_pa, x_pa, or y_pa must contain a Standardizer instance.

  • stdzr (Standardizer, optional) – Standardizer for converting ticks. Only optional if z_pa, x_pa, or y_pa contain a Standardizer instance.

  • x_scale ({'natural', 'transformed', 'standardized'}) – Space in which to plot respective array. Ignored if array is not a ParameterArray.

  • y_scale ({'natural', 'transformed', 'standardized'}) – Space in which to plot respective array. Ignored if array is not a ParameterArray.

  • z_scale ({'natural', 'transformed', 'standardized'}) – Space in which to plot respective array. Ignored if array is not a ParameterArray.

  • x_tick_scale ({'natural', 'transformed', 'standardized'}) – Space in which to label ticks for respective axis. Should be ‘natural’ or match respective *_scale argument.

  • y_tick_scale ({'natural', 'transformed', 'standardized'}) – Space in which to label ticks for respective axis. Should be ‘natural’ or match respective *_scale argument.

  • z_tick_scale ({'natural', 'transformed', 'standardized'}) – Space in which to label ticks for respective axis. Should be ‘natural’ or match respective *_scale argument.

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from gumbi import Standardizer, ParrayPlotter, ParameterArray
>>> stdzr = Standardizer(x = {'μ': -5, 'σ': 0.5},
...                      y = {'μ': -0.3, 'σ': 0.15},
...                      z={'μ': 2, 'σ': 2},
...                      log_vars=['x', 'y'], logit_vars=['z'])
>>> x = np.arange(1, 10, 0.25)
>>> y = np.arange(1, 10, 0.25)
>>> x, y = np.meshgrid(x, y)
>>> z = np.sin(np.sqrt((x - 5) ** 2 + (y - 5) ** 2))**2*0.9+0.05
>>> xyz = ParameterArray(x=x, y=y, z=z, stdzr=stdzr)

Make a natural-space contour plot with user-specified levels

>>> pp = ParrayPlotter(xyz['x'], xyz['y'], xyz['z'])
>>> pp(plt.contour, levels=8)

Use the same ParrayPlotter to make a different pseudocolor plot and add a colorbar:

>>> pcm = pp(plt.pcolormesh, shading='gouraud')
>>> cbar = pp.colorbar(pcm, ax=plt.gca())

Make a filled contour plot with x plotted in natural-space and x tick labels displayed in natural-space, y plotted in transformed space but y tick lables displayed in natural-space, and z plotted in standardized space with a colorbar displaying standardized-space tick labels:

>>> pp = ParrayPlotter(xyz['x'], xyz['y'].t, xyz['z'], z_scale='standardized', z_tick_scale='standardized')
>>> cs = pp(plt.contourf)
>>> cbar = pp.colorbar(cs)
colorbar(mappable=None, cax=None, ax=None, **kwargs)

Wrapper for matplotlib.pyplot.colorbar; adjusts ticks and labels according to plotter settings.

plot(ci=0.95, ax=None, palette=None, line_kws=None, ci_kws=None)
Parameters:
  • ci (float or None, default 0.95) – Confidence interval on \(0<\mathtt{ci}<1\). If None, no confidence intervals will be drawn.

  • ax (plt.Axes, optional) – Axes on which to plot. Defaults to plt.gca().

  • palette (str or array-like) – Name of seaborn palette or list of colors (at least two) for plotting.

  • line_kws (dict, optional) – Additional keyword arguments passed to plt.plot.

  • ci_kws (dict, optional) – Additional keyword arguments passed to :meth:plot_ci.

Returns:

ax – Axes for the plot

Return type:

plt.Axes

plot_ci(ci=0.95, ci_style='fill', center='median', ax=None, **kwargs)

Plots the confidence interval for an UncertainParameterArray.

Parameters:
  • ci (float or None, default 0.95) – Confidence interval on \(0<\mathtt{ci}<1\). If None, no confidence intervals will be drawn.

  • ci_style ({'fill', 'band', 'errorbar', 'bar'}) – Whether to plot CI using plt.fill_between (fill or band) or plt.errorbar (errorbar or bar).

  • center ({'median', 'mean'}) – Which metric to plot as midpoint if using plt.errorbar.

  • ax (plt.Axes, optional) – Axes on which to plot. Defaults to plt.gca().

  • **kwargs – Additional keyword arguments passed to plt.fill_between or plt.errorbar.

Returns:

ax – Axes for the plot

Return type:

plt.Axes