lsurf.visualization.common

Visualization Common Utilities

Shared styling, color mapping, and helper functions for all visualization modules.

Functions

add_colorbar(ax, mappable[, label, orientation])

Add colorbar to axes.

create_figure([nrows, ncols, figsize, ...])

Create figure with standard settings.

get_color_mapping(values[, cmap_name, vmin, ...])

Create color mapping for values.

get_projection_config(projection)

Get axis indices and labels for xy/xz/yz projections.

save_figure(fig, path[, dpi, bbox_inches])

Save figure with standard settings.

setup_axis_grid(ax[, xlabel, ylabel, title, ...])

Apply standard axis formatting.

wavelength_to_color(wavelength_m)

Convert wavelength (in meters) to approximate visible color.

lsurf.visualization.common.get_color_mapping(values, cmap_name='viridis', vmin=None, vmax=None)[source]

Create color mapping for values.

Parameters:
  • values (ndarray) – Values to map to colors.

  • cmap_name (str) – Matplotlib colormap name.

  • vmin (float, optional) – Value range. If None, uses data min/max.

  • vmax (float, optional) – Value range. If None, uses data min/max.

Returns:

  • colors (ndarray) – RGBA colors for each value.

  • norm (Normalize) – Normalization object.

  • sm (ScalarMappable) – ScalarMappable for colorbar.

Return type:

tuple[ndarray, Normalize, _ScalarMappable]

lsurf.visualization.common.wavelength_to_color(wavelength_m)[source]

Convert wavelength (in meters) to approximate visible color.

Parameters:

wavelength_m (float or ndarray) – Wavelength in meters.

Returns:

color – RGB color tuple(s) in [0, 1] range.

Return type:

tuple or ndarray

Notes

Uses simplified visible spectrum approximation. Wavelengths outside visible range return gray.

lsurf.visualization.common.setup_axis_grid(ax, xlabel='', ylabel='', title='', grid=True)[source]

Apply standard axis formatting.

Parameters:
  • ax (Axes) – Matplotlib axes.

  • xlabel (str) – Axis labels.

  • ylabel (str) – Axis labels.

  • title (str) – Axis title.

  • grid (bool) – Whether to show grid.

lsurf.visualization.common.add_colorbar(ax, mappable, label='', orientation='vertical')[source]

Add colorbar to axes.

Parameters:
  • ax (Axes) – Matplotlib axes.

  • mappable (ScalarMappable) – Object with color mapping.

  • label (str) – Colorbar label.

  • orientation (str) – ‘vertical’ or ‘horizontal’.

Returns:

Matplotlib colorbar object.

Return type:

colorbar

lsurf.visualization.common.create_figure(nrows=1, ncols=1, figsize=None, constrained_layout=True, **kwargs)[source]

Create figure with standard settings.

Parameters:
  • nrows (int) – Number of subplot rows and columns.

  • ncols (int) – Number of subplot rows and columns.

  • figsize (tuple, optional) – Figure size. Defaults to scaled DEFAULT_FIGSIZE.

  • constrained_layout (bool) – Use constrained layout.

  • **kwargs – Additional arguments to plt.subplots.

Returns:

  • fig (Figure) – Matplotlib figure.

  • axes (Axes or ndarray) – Axes object(s).

Return type:

tuple[Figure, Axes | ndarray]

lsurf.visualization.common.save_figure(fig, path, dpi=150, bbox_inches='tight', **kwargs)[source]

Save figure with standard settings.

Parameters:
  • fig (Figure) – Matplotlib figure.

  • path (str) – Output path.

  • dpi (int) – Resolution.

  • bbox_inches (str) – Bounding box setting.

  • **kwargs – Additional arguments to savefig.

lsurf.visualization.common.get_projection_config(projection)[source]

Get axis indices and labels for xy/xz/yz projections.

Parameters:

projection (str) – Projection plane: ‘xy’, ‘xz’, or ‘yz’.

Returns:

  • idx1 (int) – First coordinate index (0=x, 1=y, 2=z).

  • idx2 (int) – Second coordinate index.

  • xlabel (str) – Label for first axis.

  • ylabel (str) – Label for second axis.

Return type:

tuple[int, int, str, str]