pylbo.visualisation.utils

Attributes

_BACKGROUND_NAME_MAPPING

Functions

refresh_plot(→ callable)

Simple decorator, when a routine is wrapped with this the plot will be

ensure_attr_set(→ None)

Ensures that a given attribute is set.

ef_name_to_latex(→ str)

Converts an eigenfunction name to latex formatting. Numbers are replaced with a

background_name_to_latex(→ str)

Maps the background name to latex formatting.

validate_ef_name(→ str)

Returns the validated eigenfunction name.

_validate_textbox_location(→ str)

Validates the location of the textbox.

_get_textbox_axes_coords(loc, outside, width, height)

Returns the coordinates of the textbox.

add_textbox_to_axes(→ matplotlib.axes.Axes.text)

Convenience method to add a textbox to the given axes.

add_axis_label(→ matplotlib.axes.Axes.text)

Creates a textbox in one of the corners of the specified axis. This method is meant

Module Contents

pylbo.visualisation.utils._BACKGROUND_NAME_MAPPING[source]
pylbo.visualisation.utils.refresh_plot(f: callable) callable[source]

Simple decorator, when a routine is wrapped with this the plot will be cleared and redrawn on calling it. Useful for when the scaling is changed or artists are added/removed.

pylbo.visualisation.utils.ensure_attr_set(obj: Any, attr: str) None[source]

Ensures that a given attribute is set.

Parameters:
  • obj (Any) – The object to check.

  • attr (str) – The attribute to check.

Raises:

ValueError – If the attribute is not set.

pylbo.visualisation.utils.ef_name_to_latex(ef_name: str, geometry: str = 'Cartesian', real_part: bool = None) str[source]

Converts an eigenfunction name to latex formatting. Numbers are replaced with a suffix corresponding to the geometry: \((1, 2, 3)\) becomes \((x, y, z)\) for Cartesian and \((r, \theta, z)\) for cylindrical geometries. Symbols and letters are also converted to LaTeX.

Parameters:
  • ef_name (str) – The name of the eigenfunction.

  • geometry (str, optional) – The geometry of the eigenfunction. The default is “Cartesian”.

  • real_part (bool, optional) – Whether the real part of the eigenfunction is being plotted. The default is None.

pylbo.visualisation.utils.background_name_to_latex(bg_name: str) str[source]

Maps the background name to latex formatting.

Parameters:

bg_name (str) – The name of the background as given by the corresponding dictionary key.

Returns:

The latex formatted background name. If the background name has no mapping the original name is returned.

Return type:

str

pylbo.visualisation.utils.validate_ef_name(ds, ef_name: str) str[source]

Returns the validated eigenfunction name.

Parameters:
  • ds (LegolasDataSet) – The dataset containing the eigenfunctions.

  • ef_name (str) – The name of the eigenfunction.

Raises:

ValueError – If the eigenfunction name is not valid.

Returns:

The validated eigenfunction name.

Return type:

str

pylbo.visualisation.utils._validate_textbox_location(loc: str) str[source]

Validates the location of the textbox.

Parameters:

loc (str) – The location of the textbox.

Raises:

ValueError – If the location is not one of “top left”, “top right”, “bottom left” or “bottom right”.

Returns:

The validated location.

Return type:

str

pylbo.visualisation.utils._get_textbox_axes_coords(loc: str, outside: bool, width: float, height: float)[source]

Returns the coordinates of the textbox.

Parameters:
  • loc (str) – The location of the textbox.

  • outside (bool) – Whether the textbox is outside the axes.

  • width (float) – The width of the bounding box.

  • height (float) – The height of the bounding box.

Returns:

  • float – The x-coordinate of the textbox.

  • float – The y-coordinate of the textbox.

pylbo.visualisation.utils.add_textbox_to_axes(ax: matplotlib.axes.Axes, text: str, x: float, y: float, coords: str = 'axes', fs: int = 15, alpha: float = 0.2, halign: str = 'center', color: str = 'grey', textcolor: str = 'black', boxstyle: str = 'round') matplotlib.axes.Axes.text[source]

Convenience method to add a textbox to the given axes.

Parameters:
  • ax (Axes) – The axes to add the textbox to.

  • text (str) – The text to add to the textbox.

  • x (float) – The x-coordinate of the textbox.

  • y (float) – The y-coordinate of the textbox.

  • coords (str, optional) – The coordinate system of the textbox. The default is “axes”, options are “axes”, “figure”, and “data”.

  • fs (int, optional) – The fontsize of the textbox. The default is 15.

  • alpha (float, optional) – The alpha value of the textbox. The default is 0.2.

  • halign (str, optional) – The horizontal alignment of the textbox. The default is “center”.

  • color (str, optional) – The color of the textbox. The default is “grey”.

  • textcolor (str, optional) – The color of the text. The default is “black”.

  • boxstyle (str, optional) – The style of the textbox. The default is “round”.

Returns:

The textbox.

Return type:

text

pylbo.visualisation.utils.add_axis_label(ax: matplotlib.axes.Axes, text: str, loc: str = 'top left', fs: int = 15, alpha: float = 0.2, color: str = 'grey', textcolor: str = 'black', boxstyle: str = 'round', bold: bool = False, outside: bool = False) matplotlib.axes.Axes.text[source]

Creates a textbox in one of the corners of the specified axis. This method is meant to create panel labels without having to manually specify the coordinates of the textbox.

Parameters:
  • ax (Axes) – The axes to add the textbox to.

  • text (str) – The text to add to the textbox.

  • loc (str, optional) – The location of the textbox. The default is “top left”, options are “top right”, “bottom left” and “bottom right”.

  • fs (int, optional) – The fontsize of the textbox. The default is 15.

  • alpha (float, optional) – The alpha value of the textbox. The default is 0.2.

  • color (str, optional) – The color of the textbox. The default is “grey”.

  • textcolor (str, optional) – The color of the text. The default is “black”.

  • boxstyle (str, optional) – The style of the textbox. The default is “round”. If None is passed no box will be drawn.

  • bold (bool, optional) – Whether to bold the text. The default is False.

  • outside (bool, optional) – Whether to place the textbox outside of the axis. The default is False.

Raises:

ValueError – If the location is not one of “top left”, “top right”, “bottom left” or “bottom right”.

Returns:

The textbox.

Return type:

text