erlab.plotting.erplot

Convenient access to various plotting functions.

Functions

integer_ticks(axes)

class erlab.plotting.erplot.CenteredInversePowerNorm(gamma, vcenter=0, halfrange=None, clip=False)[source]

Bases: CenteredPowerNorm

Inverse power-law normalization of symmetrical data around a center.

Unlike TwoSlopeInversePowerNorm, CenteredInversePowerNorm applies an equal rate of change around the center.

Useful when mapping symmetrical data around a conceptual center e.g., data that range from -2 to 4, with 0 as the midpoint, and with equal rates of change around that midpoint.

Parameters:
  • gamma (float) – Power law exponent.

  • vcenter (float) – The data value that defines 0.5 in the normalization. Defaults to 0.

  • halfrange (float | None) – The range of data values that defines a range of 0.5 in the normalization, so that vcenter - halfrange is 0.0 and vcenter + halfrange is 1.0 in the normalization. Defaults to the largest absolute difference to vcenter for the values in the dataset.

  • clip (bool) –

    If True values falling outside the range [vmin, vmax], are mapped to 0 or 1, whichever is closer, and masked values are set to 1. If False masked values remain masked.

    Clipping silently defeats the purpose of setting the over, under, and masked colors in a colormap, so it is likely to lead to surprises; therefore the default is clip=False.

class erlab.plotting.erplot.CenteredPowerNorm(gamma, vcenter=0, halfrange=None, clip=False)[source]

Bases: CenteredNorm

Power-law normalization of symmetrical data around a center.

Unlike TwoSlopePowerNorm, CenteredPowerNorm applies an equal rate of change around the center.

Useful when mapping symmetrical data around a conceptual center e.g., data that range from -2 to 4, with 0 as the midpoint, and with equal rates of change around that midpoint.

Parameters:
  • gamma (float) – Power law exponent.

  • vcenter (float) – The data value that defines 0.5 in the normalization. Defaults to 0.

  • halfrange (float | None) – The range of data values that defines a range of 0.5 in the normalization, so that vcenter - halfrange is 0.0 and vcenter + halfrange is 1.0 in the normalization. Defaults to the largest absolute difference to vcenter for the values in the dataset.

  • clip (bool) –

    If True values falling outside the range [vmin, vmax], are mapped to 0 or 1, whichever is closer, and masked values are set to 1. If False masked values remain masked.

    Clipping silently defeats the purpose of setting the over, under, and masked colors in a colormap, so it is likely to lead to surprises; therefore the default is clip=False.

__call__(value, clip=None)[source]

Map value to the interval [0, 1].

inverse(value)[source]
class erlab.plotting.erplot.InversePowerNorm(gamma, vmin=None, vmax=None, clip=False)[source]

Bases: Normalize

Inverse power-law normalization.

Linearly map a given value to the 0-1 range and then apply an inverse power-law normalization over that range.

For values \(x\), matplotlib.colors.PowerNorm calculates \(x^\gamma\), whereas InversePowerNorm calculates \(1-x^{1/\gamma}\). This provides higher contrast for values closer to vmin.

Parameters:
  • gamma (float) – Power law normalization parameter. If equal to 1, the colormap is linear.

  • vmin (float | None) – If vmin and/or vmax is not given, they are initialized from the minimum and maximum value, respectively, of the first input processed; i.e., __call__(A) calls autoscale_None(A)

  • vmax (float | None) – If vmin and/or vmax is not given, they are initialized from the minimum and maximum value, respectively, of the first input processed; i.e., __call__(A) calls autoscale_None(A)

  • clip (bool) –

    If True values falling outside the range [vmin, vmax], are mapped to 0 or 1, whichever is closer, and masked values are set to 1. If False masked values remain masked.

    Clipping silently defeats the purpose of setting the over, under, and masked colors in a colormap, so it is likely to lead to surprises; therefore the default is clip=False.

inverse(value)[source]
class erlab.plotting.erplot.TwoSlopeInversePowerNorm(gamma, vcenter=0.0, vmin=None, vmax=None)[source]

Bases: TwoSlopePowerNorm

Inverse power-law normalization of data with a set center.

Useful when mapping data with an unequal rates of change around a conceptual center, e.g., data that range from -2 to 4, with 0 as the midpoint.

Parameters:
  • gamma (float) – Power law exponent.

  • vcenter (float) – The data value that defines 0.5 in the normalization. Defaults to 0.

  • vmin (float | None) – The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.

  • vmax (float | None) – The data value that defines 1.0 in the normalization. Defaults to the max value of the dataset.

class erlab.plotting.erplot.TwoSlopePowerNorm(gamma, vcenter=0.0, vmin=None, vmax=None)[source]

Bases: TwoSlopeNorm

Power-law normalization of data with a set center.

Useful when mapping data with an unequal rates of change around a conceptual center, e.g., data that range from -2 to 4, with 0 as the midpoint.

Parameters:
  • gamma (float) – Power law exponent.

  • vcenter (float) – The data value that defines 0.5 in the normalization. Defaults to 0.

  • vmin (float | None) – The data value that defines 0.0 in the normalization. Defaults to the min value of the dataset.

  • vmax (float | None) – The data value that defines 1.0 in the normalization. Defaults to the max value of the dataset.

__call__(value, clip=None)[source]

Map value to the interval [0, 1]. The clip argument is unused.

inverse(value)[source]
erlab.plotting.erplot.autoscale_to(arr, margin=0.2)[source]
erlab.plotting.erplot.clean_labels(axes, remove_inner_ticks=False, **kwargs)[source]

Clean the labels of the given axes.

This function removes the labels from the axes except for the outermost axes and prettifies the remaining labels with fancy_labels.

Changed in version 2.5.0: The function now calls Axes.label_outer recursively instead of setting the labels to an empty string.

Parameters:
  • axes (Iterable[Axes]) – The axes to clean the labels for.

  • remove_inner_ticks (bool) – If True, remove the inner ticks as well (not only tick labels).

  • **kwargs – Additional keyword arguments to be passed to fancy_labels.

erlab.plotting.erplot.copy_mathtext(s, fontsize=None, fontproperties=None, outline=False, svg=True, rcparams=None, **mathtext_rc)[source]
erlab.plotting.erplot.fancy_labels(ax=None, deg2rad=False)[source]
erlab.plotting.erplot.fermiline(ax=None, value=0.0, orientation='h', **kwargs)[source]

Plot a constant energy line to denote the Fermi level.

Parameters:
  • ax (Axes | None) – The matplotlib.axes.Axes to annotate.

  • value (float) – The coordinate of the line. Defaults to 0, assuming binding energy.

  • orientation (Literal['h', 'v']) – If ‘h’, a horizontal line is plotted. If ‘v’, a vertical line is plotted.

  • **kwargs – Keyword arguments passed onto matplotlib.lines.Line2D.

Return type:

matplotlib.lines.Line2D

erlab.plotting.erplot.figwh(ratio=0.6180339887498948, wide=0, wscale=1, style='aps', fixed_height=True)[source]
erlab.plotting.erplot.flatten_transparency(rgba, background=None)[source]

Flatten the transparency of an RGBA image by blending it with a background color.

Parameters:
  • rgba (ndarray[Any, dtype[_ScalarType_co]]) – The input RGBA image as a numpy array.

  • background (RGBColorType, optional) – The background color to blend with. Defaults to white.

erlab.plotting.erplot.get_bz_edge(basis, reciprocal=True, extend=None)[source]

Calculate the edge of the first Brillouin zone (BZ) from lattice vectors.

Parameters:
  • basis (ndarray[Any, dtype[float64]]) – (N, N) numpy array where N = 2``or ``3 with each row containing the lattice vectors.

  • reciprocal (bool) – If False, the basis are given in real space lattice vectors.

  • extend (tuple[int, ...] | None) – Tuple of positive integers specifying the number of times to extend the BZ in each direction. If None, only the first BZ is returned (equivalent to (1,) * N).

Returns:

  • lines (array-like) – (M, 2, N) array that specifies the endpoints of the M lines that make up the BZ edge, where N = len(basis).

  • vertices (array-like) – Vertices of the BZ.

Return type:

tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[float64]]]

erlab.plotting.erplot.get_mappable(ax, image_only=False, silent=False)[source]

Get the matplotlib.cm.ScalarMappable from a given matplotlib.axes.Axes.

Parameters:
  • ax (Axes) – Parent axes.

  • image_only (bool) – Only consider images as a valid mappable, by default False.

  • silent (bool) – If False, raises a RuntimeError when no mappable is found. If True, silently returns None.

Return type:

matplotlib.cm.ScalarMappable or None

erlab.plotting.erplot.gradient_fill(x, y, y0=None, color='C0', cmap=None, transpose=False, reverse=False, ax=None, **kwargs)[source]

Apply a gradient fill to a line plot.

Parameters:
Return type:

matplotlib.image.AxesImage

erlab.plotting.erplot.image_is_light(im)[source]

Determine if an image is light or dark.

Checks whether the prominent color is closer to white than black.

erlab.plotting.erplot.label_subplot_properties(axes, values, decimals=None, si=0, name=None, unit=None, order='C', **kwargs)[source]

Labels subplots with automatically generated labels.

Parameters:
  • axes (matplotlib.axes.Axes | Iterable[matplotlib.axes.Axes]) – matplotlib.axes.Axes to label. If an array is given, the order will be determined by the flattening method given by order.

  • values (dict) – key-value pair of annotations.

  • decimals (int | None) – Number of decimal places to round to. If decimals is None, no rounding is performed. If decimals is negative, it specifies the number of positions to the left of the decimal point.

  • si (int) – Powers of 10 for automatic SI prefix setting.

  • name (str | None) – When set, overrides automatic dimension name setting.

  • unit (str | None) – When set, overrides automatic unit setting.

  • order (Literal['C', 'F', 'A', 'K']) – Order in which to flatten ax. ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.

  • **kwargs – Extra arguments to erlab.plotting.annotations.label_subplots.

erlab.plotting.erplot.label_subplots(axes, values=None, startfrom=1, order='C', loc='upper left', offset=(0.0, 0.0), prefix='', suffix='', numeric=False, capital=False, fontweight='normal', fontsize=None, **kwargs)[source]

Labels subplots with automatically generated labels.

Parameters:
  • axes (matplotlib.axes.Axes | Iterable[matplotlib.axes.Axes]) – matplotlib.axes.Axes to label. If an array is given, the order will be determined by the flattening method given by order.

  • values (Iterable[int | str] | None) – Integer or string labels corresponding to each Axes in axes for manual labels.

  • startfrom (int) – Start from this number when creating automatic labels. Has no effect when values is not None.

  • order (Literal['C', 'F', 'A', 'K']) – Order in which to flatten ax. ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.

  • loc (Literal['upper left', 'upper center', 'upper right', 'center left', 'center', 'center right', 'lower left', 'lower center', 'lower right']) – The box location. The default is 'upper left'.

  • offset (tuple[float, float]) – Values that are used to position the legend in conjunction with loc, given in display units.

  • prefix (str) – String to prepend to the alphabet label.

  • suffix (str) – String to append to the alphabet label.

  • numeric (bool) – Use integer labels instead of alphabets.

  • capital (bool) – Capitalize automatically generated alphabetical labels.

  • fontweight (Literal['ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black']) – Set the font weight. The default is 'normal'.

  • fontsize (float | Literal['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'] | None) – Set the font size. The default is 'medium' for axes, and 'large' for figures.

  • **kwargs – Extra arguments to matplotlib.text.Text: refer to the matplotlib documentation for a list of all possible arguments.

erlab.plotting.erplot.label_subplots_nature(axes, values=None, startfrom=1, order='C', offset=(-20.0, 7.0), prefix='', suffix='', numeric=False, capital=False, fontweight='black', fontsize=8, **kwargs)[source]

Labels subplots with automatically generated labels.

Parameters:
  • axes (matplotlib.axes.Axes | Sequence[matplotlib.axes.Axes]) – matplotlib.axes.Axes to label. If an array is given, the order will be determined by the flattening method given by order.

  • values (Sequence[int | str] | None) – Integer or string labels corresponding to each Axes in axes for manual labels.

  • startfrom (int) – Start from this number when creating automatic labels. Has no effect when values is not None.

  • order (Literal['C', 'F', 'A', 'K']) – Order in which to flatten ax. ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.

  • offset (tuple[float, float]) – Values that are used to position the labels, given in points.

  • prefix (str) – String to prepend to the alphabet label.

  • suffix (str) – String to append to the alphabet label.

  • numeric (bool) – Use integer labels instead of alphabets.

  • capital (bool) – Capitalize automatically generated alphabetical labels.

  • fontweight (Literal['ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman', 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black']) – Set the font weight. The default is 'normal'.

  • fontsize (float | Literal['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large']) – Set the font size. The default is 'medium' for axes, and 'large' for figures.

  • **kwargs – Extra arguments to matplotlib.text.Text: refer to the matplotlib documentation for a list of all possible arguments.

erlab.plotting.erplot.mark_points(points, labels, y=0.0, pad=(0, 1.75), literal=False, roman=True, bar=False, ax=None, **kwargs)[source]

Mark points above the horizontal axis.

Useful when annotating high symmetry points along a cut.

Parameters:
  • points (Sequence[float]) – Floats indicating the position of each label.

  • labels (Sequence[str]) – Sequence of label strings indicating a high symmetry point. Must be the same length as points.

  • y (float | Sequence[float]) – Position of the label in data coordinates

  • pad (tuple[float, float]) – Offset of the text in points.

  • literal (bool) – If True, take the input string literally.

  • roman (bool) – If False, True, itallic fonts are used.

  • bar (bool) – If True, prints a bar over the label.

  • ax (matplotlib.axes.Axes | Iterable[matplotlib.axes.Axes] | None) – matplotlib.axes.Axes to annotate.

erlab.plotting.erplot.mark_points_outside(points, labels, axis='x', roman=True, bar=False, ax=None)[source]

Mark points above the horizontal axis.

Useful when annotating high symmetry points along a cut.

Parameters:
  • points (Sequence[float]) – Floats indicating the position of each label.

  • labels (Sequence[str]) – Sequence of label strings indicating a high symmetry point. Must be the same length as points.

  • axis (Literal['x', 'y']) – If 'x', marks points along the horizontal axis. If 'y', marks points along the vertical axis.

  • roman (bool) – If False, True, itallic fonts are used.

  • bar (bool) – If True, prints a bar over the label.

  • ax (matplotlib.axes.Axes | Iterable[matplotlib.axes.Axes] | None) – matplotlib.axes.Axes to annotate.

erlab.plotting.erplot.nice_colorbar(ax=None, mappable=None, width=8.0, aspect=5.0, pad=3.0, minmax=False, orientation='vertical', floating=False, ticklabels=None, **kwargs)[source]

Create a colorbar with fixed width and aspect to ensure uniformity of plots.

Parameters:
  • ax (Axes | Iterable[Axes] | None) – The matplotlib.axes.Axes instance in which the colorbar is drawn.

  • mappable (ScalarMappable | None) – The mappable whose colormap and norm will be used.

  • width (float) – The width of the colorbar in points.

  • aspect (float) – aspect ratio of the colorbar.

  • pad (float) – The pad between the colorbar and axes in points.

  • minmax (bool) – If False, the ticks and the ticklabels will be determined from the keyword arguments (the default). If True, the minimum and maximum of the colorbar will be labeled.

  • orientation (Literal['vertical', 'horizontal']) – Colorbar orientation.

  • **kwargs – Keyword arguments are passed to proportional_colorbar.

Returns:

cbar – The created colorbar.

Return type:

matplotlib.colorbar.Colorbar

erlab.plotting.erplot.place_inset(parent_axes, width, height, pad=0.1, loc='upper right', **kwargs)[source]

Easy placement of inset axes.

Parameters:
  • parent_axes (Axes) – matplotlib.axes.Axes to place the inset axes.

  • width (float | str) – Size of the inset axes to create. If float, specifies the size in inches, e.g. 1.3. If str, specifies the size in relative units, e.g. '40%' of parent_axes.

  • height (float | str) – Size of the inset axes to create. If float, specifies the size in inches, e.g. 1.3. If str, specifies the size in relative units, e.g. '40%' of parent_axes.

  • pad (float | tuple[float, float]) – Padding between parent_axes and inset in inches.

  • loc (Literal['upper left', 'upper center', 'upper right', 'center left', 'center', 'center right', 'lower left', 'lower center', 'lower right']) – Location to place the inset axes.

  • **kwargs – Keyword arguments are passed onto matplotlib.axes.Axes.inset_axes.

Return type:

matplotlib.axes.Axes

erlab.plotting.erplot.plot_array(arr, ax=None, *, colorbar=False, colorbar_kw=None, gamma=1.0, norm=None, xlim=None, ylim=None, crop=False, rad2deg=False, func=None, func_args=None, rtol=1.0e-5, atol=1.0e-8, **improps)[source]

Plot a 2D xarray.DataArray using matplotlib.pyplot.imshow().

Parameters:
  • arr (xr.DataArray) – A two-dimensional xarray.DataArray with evenly spaced coordinates.

  • ax (matplotlib.axes.Axes | None) – The target matplotlib.axes.Axes.

  • colorbar (bool) – Whether to plot a colorbar.

  • colorbar_kw (dict | None) – Keyword arguments passed onto erlab.plotting.colors.nice_colorbar().

  • xlim (float | tuple[float, float] | None) – If given a sequence of length 2, those values are set as the lower and upper limits of each axis. If given a single float, the limits are set as (-lim, lim). If None, automatically determines the limits from the data.

  • ylim (float | tuple[float, float] | None) – If given a sequence of length 2, those values are set as the lower and upper limits of each axis. If given a single float, the limits are set as (-lim, lim). If None, automatically determines the limits from the data.

  • rad2deg (bool | Iterable[str]) – If True, converts some known angle coordinates from radians to degrees. If an iterable of str is given, only the coordinates that correspond to the given strings are converted.

  • func (Callable | None) – A callable that processes the values prior to display. Its output must have the same shape as the input.

  • func_args (dict | None) – Keyword arguments passed onto func.

  • rtol (float) – By default, the input array is checked for evenly spaced coordinates. rtol and atol are the tolerances for the coordinates to be considered evenly spaced. The default values are consistent with numpy.isclose.

  • atol (float) – By default, the input array is checked for evenly spaced coordinates. rtol and atol are the tolerances for the coordinates to be considered evenly spaced. The default values are consistent with numpy.isclose.

  • **improps – Keyword arguments passed onto matplotlib.axes.Axes.imshow().

Return type:

matplotlib.image.AxesImage

erlab.plotting.erplot.plot_array_2d(larr, carr, ax=None, *, normalize_with_larr=False, xlim=None, ylim=None, cmap=None, lnorm=None, cnorm=None, background=None, colorbar=True, cax=None, colorbar_kw=None, imshow_kw=None, N=256, rtol=1.0e-5, atol=1.0e-8, **indexers_kwargs)[source]

Plot a 2D array with associated color array.

The lightness array represents the intensity values, while the color array represents some other property. The arrays must have the same shape.

Parameters:
  • larr (xr.DataArray) – The 2D array representing the lightness values.

  • carr (xr.DataArray) – The 2D array representing the color values.

  • ax (matplotlib.axes.Axes | None) – The axes on which to plot the array. If None, the current axes will be used.

  • normalize_with_larr (bool) – Whether to normalize the color array with the lightness array. Default is False.

  • xlim (float | tuple[float, float] | None) – The x-axis limits for the plot. If a float, it represents the symmetric limits around 0. If a tuple, it represents the lower and upper limits. If None, the limits are determined from the data.

  • ylim (float | tuple[float, float] | None) – The y-axis limits for the plot. If a float, it represents the symmetric limits around 0. If a tuple, it represents the lower and upper limits. If None, the limits are determined from the data.

  • cmap (matplotlib.colors.Colormap | str | None) – The colormap to use for the color array. If None, a linear segmented colormap consisting of blue, black, and red is used.

  • lnorm (matplotlib.colors.Normalize | None) – The normalization object for the lightness array.

  • cnorm (matplotlib.colors.Normalize | None) – The normalization object for the color array.

  • background (ColorType | None) – The background color to use for the plot. If None, white is used.

  • colorbar (bool) – Whether to create a colorbar. Default is True.

  • cax (matplotlib.axes.Axes | None) – The axes on which to create the colorbar if colorbar is True. If None, a new axes will be created for the colorbar.

  • colorbar_kw (dict | None) – Additional keyword arguments to pass to matplotlib.pyplot.colorbar.

  • imshow_kw (dict | None) – Additional keyword arguments to pass to matplotlib.pyplot.imshow.

  • N (int) – The number of levels in the colormap. Default is 256.

  • rtol (float) – By default, the input array is checked for evenly spaced coordinates. rtol and atol are the tolerances for the coordinates to be considered evenly spaced. The default values are consistent with numpy.isclose.

  • atol (float) – By default, the input array is checked for evenly spaced coordinates. rtol and atol are the tolerances for the coordinates to be considered evenly spaced. The default values are consistent with numpy.isclose.

  • **indexers_kwargs (dict) – Additional keyword arguments to pass to qsel to select the data to plot. Note that the resulting data after the selection must be 2D.

Returns:

Return type:

tuple[matplotlib.image.AxesImage, matplotlib.colorbar.Colorbar | None]

Example

>>> import erlab.plotting.erplot as eplt
>>> import matplotlib.pyplot as plt
>>> import xarray as xr
>>> larr = xr.DataArray([[1, 2, 3], [4, 5, 6]])
>>> carr = xr.DataArray([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]])
>>> eplt.plot_array_2d(larr, carr)
erlab.plotting.erplot.plot_hex_bz(a=3.54, rotate=0.0, offset=(0.0, 0.0), reciprocal=True, ax=None, **kwargs)[source]

Plot a 2D hexagonal BZ overlay on the specified axes.

erlab.plotting.erplot.plot_hv_text(ax, val, x=0.025, y=0.975, **kwargs)[source]
erlab.plotting.erplot.plot_slices(maps, figsize=None, *, transpose=False, xlim=None, ylim=None, crop=True, same_limits=False, axis='auto', show_all_labels=False, colorbar='none', hide_colorbar_ticks=True, annotate=True, cmap=None, norm=None, order='C', cmap_order='C', norm_order=None, gradient=False, gradient_kw=None, subplot_kw=None, annotate_kw=None, colorbar_kw=None, axes=None, **values)[source]

Automated comparison plot of slices.

Parameters:
  • maps (xr.DataArray | Sequence[xr.DataArray]) – Arrays to plot.

  • figsize (tuple[float, float] | None) – Figure size.

  • transpose (bool) – Transpose each map before plotting.

  • xlim (float | tuple[float, float] | None) – If given a sequence of length 2, those values are set as the lower and upper limits of each axis. If given a single float, the limits are set as (-lim, lim). If None, automatically determines the limits from the data.

  • ylim (float | tuple[float, float] | None) – If given a sequence of length 2, those values are set as the lower and upper limits of each axis. If given a single float, the limits are set as (-lim, lim). If None, automatically determines the limits from the data.

  • crop (bool) – If True, crops the data to the limits given by xlim and ylim prior to plotting.

  • same_limits (bool) – If True, all images will have the same vmin and vmax.

  • axis (Literal['on', 'off', 'equal', 'scaled', 'tight', 'auto', 'image', 'scaled', 'square']) –

    Passed onto matplotlib.axes.Axes.axis(). Possible values are:

    Value

    Description

    ’on’

    Turn on axis lines and labels.

    ’off’

    Turn off axis lines and labels.

    ’equal’

    Set equal scaling (i.e., make circles circular) by changing axis limits. This is the same as ax.set_aspect('equal', adjustable='datalim'). Explicit data limits may not be respected in this case.

    ’scaled’

    Set equal scaling (i.e., make circles circular) by changing dimensions of the plot box. This is the same as ax.set_aspect('equal', adjustable='box', anchor='C'). Additionally, further autoscaling will be disabled.

    ’tight’

    Set limits just large enough to show all data, then disable further autoscaling.

    ’auto’

    Automatic scaling (fill plot box with data).

    ’image’

    ’scaled’ with axis limits equal to data limits.

    ’square’

    Square plot; similar to ‘scaled’, but initially forcing xmax-xmin == ymax-ymin.

  • show_all_labels (bool) – If True, shows every xlabel and ylabel. If False, labels on shared axes are minimized. When False and the axes argument is given, the order must be specified to correctly hide shared labels.

  • colorbar (Literal['none', 'right', 'rightspan', 'all']) –

    Controls colorbar behavior. Possible values are:

    Value

    Description

    ’none’

    Do not show colorbars.

    ’right’

    Creates a colorbar on the right for each row.

    ’rightspan’

    Create a single colorbar that spans all axes.

    ’all’

    Plot a colorbar for every axes.

  • hide_colorbar_ticks (bool) – If True, hides colorbar ticks.

  • annotate (bool) – If False, turn off automatic annotation.

  • cmap (str | matplotlib.colors.Colormap | Iterable[str | matplotlib.colors.Colormap | Iterable[matplotlib.colors.Colormap | str]] | None) – If supplied a single str or matplotlib.colors.Colormap, the colormap is applied to all axes. Otherwise, a nested sequence with the same shape as the resulting axes can be provided to use different colormaps for different axes. If the slices are 1D, this argument can be used to supply valid colors as line colors for differnet slices.

  • norm (matplotlib.colors.Normalize | Iterable[matplotlib.colors.Normalize | Iterable[matplotlib.colors.Normalize]] | None) – If supplied a single matplotlib.colors.Normalize, the norm is applied to all axes. Otherwise, a nested sequence with the same shape as the resulting axes can be provided to use different norms for different axes.

  • order (Literal['C', 'F']) – Order to display the data. Effectively, this determines if each map is displayed along the same row or the same column. ‘C’ means to flatten in row-major (C-style) order, and ‘F’ means to flatten in column-major (Fortran-style) order.

  • cmap_order (Literal['C', 'F']) – The order to flatten when given a nested sequence for cmap, Defaults to order.

  • norm_order (Literal['C', 'F'] | None) – The order to flatten when given a nested sequence for norm, Defaults to cmap_order.

  • gradient (bool) – If True, for 1D slices, fills the area under the curve with a gradient. Has no effect for 2D slices.

  • gradient_kw (dict | None) – Extra arguments to gradient_fill().

  • subplot_kw (dict | None) – Extra arguments to matplotlib.pyplot.subplots(): refer to the matplotlib documentation for a list of all possible arguments.

  • annotate_kw (dict | None) – Extra arguments to erlab.plotting.annotations.label_subplot_properties(). Only applied when annotate is True.

  • colorbar_kw (dict | None) – Extra arguments to erlab.plotting.colors.proportional_colorbar().

  • axes (Iterable[matplotlib.axes.Axes] | None) – A nested sequence of matplotlib.axes.Axes. If supplied, the returned matplotlib.figure.Figure is inferred from the first axes.

  • **values – Key-value pair of cut location and bin widths. See examples. Remaining arguments are passed onto plot_array().

Returns:

Return type:

tuple[matplotlib.figure.Figure, Iterable[matplotlib.axes.Axes]]

Examples

# Two maps: map1, map2
# Create a figure with a 3 by 2 grid.

fig, axes = plot_slices([map1, map2], eV=[0, -0.1, -0.2], eV_width=0.05)
erlab.plotting.erplot.property_label(key, value, decimals=None, si=0, name=None, unit=None)[source]
erlab.plotting.erplot.proportional_colorbar(mappable=None, cax=None, ax=None, **kwargs)[source]

Replace the current colorbar or creates a new colorbar with proportional spacing.

The default behavior of colorbars in matplotlib does not support colors proportional to data in different norms. This function circumvents this behavior.

Parameters:
  • mappable (ScalarMappable | None) – The matplotlib.cm.ScalarMappable described by this colorbar.

  • cax (Axes | None) – Axes into which the colorbar will be drawn.

  • ax (Axes | Iterable[Axes] | None) – One or more parent axes from which space for a new colorbar axes will be stolen, if cax is None. This has no effect if cax is set. If mappable is None and ax is given with more than one Axes, the function will try to infer the mappable from the first one.

  • **kwargs – Extra arguments to matplotlib.pyplot.colorbar: refer to the matplotlib documentation for a list of all possible arguments.

Returns:

cbar – The created colorbar.

Return type:

matplotlib.colorbar.Colorbar

Examples

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors

# Create example data and plot
X, Y = np.mgrid[0 : 3 : complex(0, 100), 0 : 2 : complex(0, 100)]
pcm = plt.pcolormesh(
    X,
    Y,
    (1 + np.sin(Y * 10.0)) * X**2,
    norm=matplotlib.colors.PowerNorm(gamma=0.5),
    cmap="Blues_r",
    shading="auto",
)

# Plot evenly spaced colorbar
proportional_colorbar()
erlab.plotting.erplot.scale_units(ax, axis, si=0, *, prefix=True, power=False)[source]

Rescales ticks and adds an SI prefix to the axis label.

Useful when you want to rescale the ticks without actually rescaling the data. For example, when plotting a cut from a low pass energy scan, you might want to convert the energy units from eV to meV.

Using this function on an axis where the major locator is not the default formatter matplotlib.ticker.ScalarFormatter will result in undefined behavior.

Parameters:
  • ax (matplotlib.axes.Axes | Iterable[matplotlib.axes.Axes]) – _description_

  • axis (Literal['x', 'y', 'z']) – The axis you wish to rescale.

  • si (int) – Exponent of 10 corresponding to a SI prefix.

  • prefix (bool) – If True, tries to detect the unit from the axis label and scales it accordingly. The scaling behaviour is controlled by the power argument. If no units are found in the axis label, it is silently ignored.

  • power (bool) – If False, prefixes the detected unit on the axis label with a SI prefix corresponding to si. If True, the unit is prefixed with a scientific notation instead.

erlab.plotting.erplot.set_titles(axes, labels, order='C', **kwargs)[source]
erlab.plotting.erplot.set_xlabels(axes, labels, order='C', **kwargs)[source]
erlab.plotting.erplot.set_ylabels(axes, labels, order='C', **kwargs)[source]
erlab.plotting.erplot.sizebar(ax, value, unit, si=0, resolution=1.0, decimals=0, label=None, loc='lower right', pad=0.1, borderpad=0.5, sep=3.0, frameon=False, **kwargs)[source]

Add a size bar to an axes.

Parameters:
  • ax (Axes) – The matplotlib.axes.Axes instance to place the size bar in.

  • value (float) – Length of the size bar in terms of unit.

  • unit (str) – An SI unit string without prefixes.

  • si (int) – Exponents that have a corresponding SI prefix

  • resolution (float) – Value to scale the data coordinates in terms of unit.

  • decimals (int) – Number of decimals on the size bar label.

  • label (str | None) – When provided, overrides the automatically generated label string.

  • loc (Literal['upper left', 'upper center', 'upper right', 'center left', 'center', 'center right', 'lower left', 'lower center', 'lower right']) – Location of the size bar.

  • pad (float) – Padding around the label and size bar, in fraction of the font size.

  • borderpad (float) – Border padding, in fraction of the font size.

  • sep (float) – Separation between the label and the size bar, in points.

  • frameon (bool) – If True, draw a box around the horizontal bar and label.

  • **kwargs – Keyword arguments forwarded to mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar.

erlab.plotting.erplot.unify_clim(axes, target=None, image_only=False)[source]

Unify the color limits for mappables in multiple axes.

Parameters:
  • axes (ndarray) – Array of matplotlib.axes.Axes to unify the color limits.

  • target (Axes | None) – The target axis to unify the color limits. If provided, the target color limits will be taken from this axes. Otherwise, the color limits will be set to include all mappables in the axes.

  • image_only (bool) – If True, only consider mappables that are images. Default is False.