Skip to content

PixelMap

eitprocessing.plotting.pixelmap.PixelMapPlotting dataclass

PixelMapPlotting(pixel_map: PixelMap | PixelMask)

Utility class for plotting pixel maps and masks.

config property

config: PixelMapPlotConfig

Plotting configuration for pixel maps and pixel masks.

imshow

imshow(
    colorbar: bool | None = None,
    normalize: bool | None = None,
    percentage: bool | None = None,
    absolute: bool | None = None,
    colorbar_kwargs: dict | None = None,
    facecolor: ColorType | None = None,
    hide_axes: bool | None = None,
    **kwargs
) -> AxesImage

Display the pixel map or mask using imshow.

This method is a wrapper around matplotlib.pyplot.imshow that provides convenient defaults and formatting options for displaying pixel maps and masks.

Plotting configuration is taken from plot_config, unless overridden by explicit arguments. Any additional keyword arguments are merged with plot_config.extra_kwargs and passed to matplotlib.pyplot.imshow.

If colorbar is True, a colorbar is added to the axes. If normalize is True, the pixel values are scaled by their maximum value before plotting. The appearance of the colorbar can be modified using percentage and absolute flags:

  • percentage=True displays the colorbar in percentage units (where 1.0 → 100%).
  • absolute=True uses the absolute value of the data for color scaling and labeling.

If the colormap has underflow or overflow colors (e.g., for negative values), the colorbar will extend accordingly. Additional arguments can be passed to control or override the appearance of the colorbar via colorbar_kwargs, which are passed directly to matplotlib.pyplot.colorbar.

If hide_axes is True, the axis ticks and labels are hidden (but the axes remain visible to retain background styling such as facecolor).

Additional keyword arguments are passed directly to imshow, allowing for full control over image rendering. Notably, you can pass an existing matplotlib Axes object using the ax keyword argument.

PARAMETER DESCRIPTION
colorbar

Whether to display a colorbar.

TYPE: bool | None DEFAULT: None

normalize

Whether to scale by the maximum value.

TYPE: bool | None DEFAULT: None

percentage

Whether to display the colorbar values as a percentage.

TYPE: bool | None DEFAULT: None

absolute

Whether to display the colorbar using absolute values.

TYPE: bool | None DEFAULT: None

colorbar_kwargs

Additional arguments passed to matplotlib.pyplot.colorbar.

TYPE: dict DEFAULT: None

facecolor

Background color for the axes. If None, uses the facecolor of the PixelMap.

TYPE: ColorType | None DEFAULT: None

hide_axes

Whether to hide the axes ticks and labels.

TYPE: bool | None DEFAULT: None

ax

Axes to plot on. If not provided, uses the current axes.

TYPE: Axes

**kwargs

Additional keyword arguments passed to matplotlib.pyplot.imshow.

DEFAULT: {}

RETURNS DESCRIPTION
AxesImage

The image object created by imshow.

TYPE: AxesImage

contour

contour(**kwargs) -> ContourSet

Create a contour plot of the pixel map or mask.

This method uses matplotlib.pyplot.contour to create a contour plot of the pixel map values.

PARAMETER DESCRIPTION
**kwargs

Additional keyword arguments passed to matplotlib.pyplot.contour.

DEFAULT: {}

RETURNS DESCRIPTION
QuadContourSet

The contour set created by the contour function.

TYPE: ContourSet

surface

surface(**kwargs) -> Poly3DCollection

Create a 3D surface plot of the pixel map or mask.

This method uses matplotlib.pyplot.axes3d.plot_surface to create a 3D surface plot of the pixel map values.

PARAMETER DESCRIPTION
**kwargs

Additional keyword arguments passed to matplotlib.pyplot.axes3d.plot_surface.

DEFAULT: {}

RETURNS DESCRIPTION
Axes3D

The 3D axes object containing the surface plot.

TYPE: Poly3DCollection

add_region_markers

add_region_markers(
    ax: Axes, label_map: dict | None = None, **kwargs
) -> list[Text]

Add markers to an integer map plot.

This methods adds text labels at the center of all pixels with the same label, assuming continuous regions where the center of mass is inside the region itself. If the regions are not continuous, the label is placed in the largest region. If the center of mass of the region is outside the region, the label position is determined by repeatedly eroding the region (using scipy.ndimage.erosion).

By default, the text labels are the integer values converted to strings. You can customize labels by providing a dictionary label_map, mapping the integer values to custom labels.

Center of mass

For any regular shape, the center of mass is near the geometrical center of a region. However, for e.g. a C-shaped region, the center of mass might fall outside the region itself.

PARAMETER DESCRIPTION
ax

The axes to add the markers to.

TYPE: Axes

label_map

A dictionary mapping integer labels to string labels. If None, the integer label itself is used.

TYPE: dict | None DEFAULT: None

**kwargs

Additional keyword arguments passed to the text function, such as color and fontsize.

DEFAULT: {}

RETURNS DESCRIPTION
list[Text]

list[mpl.text.Text]: A list of text objects created for the labels.