holodeck.plot

Plotting module.

Provides convenience methods for generating standard plots and components using matplotlib.

class holodeck.plot.MidpointLogNormalize(vmin=None, vmax=None, midpoint=0.0, clip=False)[source]
class holodeck.plot.MidpointNormalize(vmin=None, vmax=None, midpoint=0.0, clip=False)[source]

Normalise the colorbar so that diverging bars work there way either side from a prescribed midpoint value)

e.g. im=ax1.imshow(array, norm=MidpointNormalize(midpoint=0.,vmin=-100, vmax=100))

holodeck.plot.figax(figsize=[7, 5], ncols=1, nrows=1, sharex=False, sharey=False, squeeze=True, scale=None, xscale='log', xlabel='', xlim=None, yscale='log', ylabel='', ylim=None, left=None, bottom=None, right=None, top=None, hspace=None, wspace=None, widths=None, heights=None, grid=True, **kwargs)[source]

Create matplotlib figure and axes instances.

Convenience function to create fig/axes using plt.subplots, and quickly modify standard parameters.

Parameters:
  • figsize ((2,) list, optional) – Figure size in inches.

  • ncols (int, optional) – Number of columns of axes.

  • nrows (int, optional) – Number of rows of axes.

  • sharex (bool, optional) – Share xaxes configuration between axes.

  • sharey (bool, optional) – Share yaxes configuration between axes.

  • squeeze (bool, optional) – Remove dimensions of length (1,) in the axes object.

  • scale ([type], optional) – Axes scaling to be applied to all x/y axes. One of [‘log’, ‘lin’].

  • xscale (str, optional) – Axes scaling for xaxes [‘log’, ‘lin’].

  • xlabel (str, optional) – Label for xaxes.

  • xlim ([type], optional) – Limits for xaxes.

  • yscale (str, optional) – Axes scaling for yaxes [‘log’, ‘lin’].

  • ylabel (str, optional) – Label for yaxes.

  • ylim ([type], optional) – Limits for yaxes.

  • left ([type], optional) – Left edge of axes space, set using plt.subplots_adjust(), as a fraction of figure.

  • bottom ([type], optional) – Bottom edge of axes space, set using plt.subplots_adjust(), as a fraction of figure.

  • right ([type], optional) – Right edge of axes space, set using plt.subplots_adjust(), as a fraction of figure.

  • top ([type], optional) – Top edge of axes space, set using plt.subplots_adjust(), as a fraction of figure.

  • hspace ([type], optional) – Height space between axes if multiple rows are being used.

  • wspace ([type], optional) – Width space between axes if multiple columns are being used.

  • widths ([type], optional) –

  • heights ([type], optional) –

  • grid (bool, optional) – Add grid lines to axes.

Returns:

  • fig (matplotlib.figure.Figure) – New matplotlib figure instance containing axes.

  • axes ([ndarray] matplotlib.axes.Axes) – New matplotlib axes, either a single instance or an ndarray of axes.

holodeck.plot.plot_bg_ss(fobs, bg, ss=None, bglabel=None, sslabel=None, xlabel='GW Frequency $[\\mathrm{yr}^{-1}]$', ylabel='GW Characteristic Strain', **kwargs)[source]

Can plot strain or power spectral density, just need to set ylabel accordingly

holodeck.plot.scientific_notation(val, man=1, exp=0, dollar=True)[source]

Convert a scalar into a string with scientific notation (latex formatted).

Parameters:
  • val (scalar) – Numerical value to convert.

  • man (int or None) – Precision of the mantissa (decimal points); or None for omit mantissa.

  • exp (int or None) – Precision of the exponent (decimal points); or None for omit exponent.

  • dollar (bool) – Include dollar-signs (‘$’) around returned expression.

Returns:

rv_str – Scientific notation string using latex formatting.

Return type:

str

holodeck.plot.smap(args=[0.0, 1.0], cmap=None, log=False, norm=None, midpoint=None, under='0.8', over='0.8', left=None, right=None)[source]

Create a colormap from a scalar range to a set of colors.

Parameters:
  • args (scalar or array_like of scalar) – Range of valid scalar values to normalize with

  • cmap (None, str, or matplotlib.colors.Colormap object) – Colormap to use.

  • log (bool) – Logarithmic scaling

  • norm (None or matplotlib.colors.Normalize) – Normalization to use.

  • under (str or None) – Color specification for values below range.

  • over (str or None) – Color specification for values above range.

  • left (float {0.0, 1.0} or None) – Truncate the left edge of the colormap to this value. If None, 0.0 used (if right is provided).

  • right (float {0.0, 1.0} or None) – Truncate the right edge of the colormap to this value If None, 1.0 used (if left is provided).

Returns:

smap – Scalar mappable object which contains the members: norm, cmap, and the function to_rgba.

Return type:

matplotlib.cm.ScalarMappable

holodeck.plot.truncate_colormap(cmap, minval=0.0, maxval=1.0, n=100)[source]

https://stackoverflow.com/a/18926541