Plots Module

Methods related for visual inspection of data

@author: Antony Vamvakeros

nDTomo.methods.plots.closefigs()[source]

Close all open matplotlib figures.

nDTomo.methods.plots.create_complist_imgs(components, xpix, ypix)[source]

Convert a 2D array of flattened components into a list of reshaped images and legend titles.

Parameters:
  • components (ndarray) – 2D array where each row is a flattened image (n_components x n_pixels).

  • xpix (int) – Width of each image in pixels.

  • ypix (int) – Height of each image in pixels.

Returns:

A tuple (imagelist, legendlist) where: - imagelist is a list of 2D arrays shaped as (xpix, ypix). - legendlist is a list of string labels like ‘Component 1’, ‘Component 2’, etc.

Return type:

tuple

nDTomo.methods.plots.create_complist_spectra(components)[source]

Convert a 2D array of spectral components into a list of 1D spectra and corresponding labels.

Parameters:

components (ndarray) – 2D array where each row is a spectral component.

Returns:

A tuple (splist, legendlist) where: - splist is a list of 1D spectral arrays. - legendlist is a list of string labels like ‘Component 1’, ‘Component 2’, etc.

Return type:

tuple

nDTomo.methods.plots.nDTomo_colormap()[source]

Create a custom colormap based on ‘jet’ with zero value mapped to black.

Returns:

Modified jet colormap with the first color (zero value) set to black.

Return type:

matplotlib.colors.ListedColormap

nDTomo.methods.plots.plotfigs_imgs(imagelist, legendlist=None, rows=1, cols=5, figsize=(20, 3), cl=True, cmap='jet')[source]

Plot a grid of 2D images with optional legends, colorbars, and custom layout.

Parameters:
  • imagelist (list of ndarray) – List of 2D arrays to display as images.

  • legendlist (list of str, optional) – List of titles for each subplot. If None, default labels like ‘Component 1’ will be used.

  • rows (int, optional) – Number of subplot rows (default is 1).

  • cols (int, optional) – Number of subplot columns (default is 5).

  • figsize (tuple, optional) – Size of the entire figure in inches (default is (20, 3)).

  • cl (bool, optional) – If True, display colorbar for each subplot (default is True).

  • cmap (str or Colormap, optional) – Colormap used for displaying the images (default is ‘jet’).

nDTomo.methods.plots.plotfigs_spectra(spectralist, legendlist=None, xaxis=None, rows=1, cols=5, figsize=(20, 3))[source]

Plot a grid of spectra in a subplot layout with optional legends and custom x-axis.

Parameters:
  • spectralist (list of ndarray) – List of 1D arrays representing spectra.

  • legendlist (list of str, optional) – Titles for each subplot. If None, default labels like ‘Component 1’ will be used.

  • xaxis (ndarray, optional) – Shared x-axis for all spectra. If None, the index of the spectrum is used.

  • rows (int, optional) – Number of subplot rows (default is 1).

  • cols (int, optional) – Number of subplot columns (default is 5).

  • figsize (tuple, optional) – Size of the figure in inches (default is (20, 3)).

nDTomo.methods.plots.showim(im, fignum=1, clim=None, cmap='jet')[source]

Display a 2D image using matplotlib with optional colormap and color limits.

Parameters:
  • im (array-like) – 2D array representing the image to display.

  • fignum (int, optional) – Figure number for the matplotlib window (default is 1).

  • clim (tuple of float, optional) – Tuple specifying the color limits (vmin, vmax). If None, uses data min/max.

  • cmap (str or Colormap, optional) – Colormap to use for image display (default is ‘jet’).

nDTomo.methods.plots.showplot(spectrum, fignum=1)[source]

Display a 1D spectrum using matplotlib.

Parameters:
  • spectrum (array-like) – 1D array containing the spectrum to be plotted.

  • fignum (int, optional) – Figure number for the matplotlib window (default is 1).

nDTomo.methods.plots.showspectra(spectra, labels=None, fig_num=1)[source]

Display multiple spectra on a single plot.

Parameters:
  • spectra (list of np.ndarray) – List of 1D arrays representing the spectra to be plotted.

  • labels (list of str, optional) – Labels for each spectrum. If None, no legend is shown.

  • fig_num (int, optional) – Figure number to use for the plot.