Skip to content

Plotting

Plot processed images.

Functions:

Name Description
generate_gif

Generate a GIF of all slices through the image.

plot_all_layers

Plot a three-dimensional numpy array.

plot_area_by_layer

Plot the layer v total area of pores within it.

plot_layer

Plot a two-dimensional numpy array.

plot_pores_by_layer

Plot the layer v number of pores within it.

generate_gif

generate_gif(
    sliced_segments, outdir, img_name, duration=100, loop=0
)

Generate a GIF of all slices through the image.

Parameters:

Name Type Description Default

sliced_segments

NDArray

A three-dimensional array of slices through the image.

required

outdir

Path

Where to save the image to.

required

img_name

str

The original image filename, will have .gif extension added.

required

duration

int

Duration between frames in the GIF, default is 100.

100

loop

int

Whether to loop the image, default is 0 which doesn't loop.

0

plot_all_layers

plot_all_layers(
    array,
    img_name=None,
    outdir=None,
    format=None,
    cmap=None,
)

Plot a three-dimensional numpy array.

This function calls plot_layer() for each "slice" of a three-dimensional array.

Parameters:

Name Type Description Default

array

NDArray

Two-dimensional numpy array to be plotted, may be labelled or unlabelled data.

required

img_name

str

The image name from which the data is derived.

None

outdir

str | Path

Target output directory, will be created if it does not exist.

None

format

str

Image format for creating image. Default is png.

None

cmap

str | ColorType

Colormap to plot as, defaults to black for binary images, viridis for heights. Labelled images are plotted as is.

None

Returns:

Type Description
dict[int, tuple[Figure, Axes]]

Dictionary of Matplotlib Figure and Axes indexed by layer.

plot_area_by_layer

plot_area_by_layer(
    area_per_layer,
    img_name=None,
    min_size=None,
    outdir=None,
    format=None,
    fwhm=None,
    log=False,
    grid=False,
)

Plot the layer v total area of pores within it.

Parameters:

Name Type Description Default

area_per_layer

list[list[float]]

A list of the total area of pores within each layer.

required

img_name

str

Image name.

None

min_size

float

Minimum size of objects to include when summing the area by layer.

None

outdir

str | Path

Output directory, if no None the image is saved there as <img_name>_pores_per_layer_[log].<format>.

None

format

str

Output file format as a string, defaults to png if not specified.

None

fwhm

tuple[int, int]

Full width half max limits for subsetting the data.

None

log

bool

Whether to plot with the logarithm (base10) of the number of pores.

False

grid

bool

Whether to include a grid on the plot.

False

Returns:

Type Description
tuple[Figure, Axes]

Returns a tuple of Matplotlib fig and ax.

plot_layer

plot_layer(
    array,
    img_name=None,
    layer=None,
    outdir=None,
    format=None,
    cmap=None,
)

Plot a two-dimensional numpy array.

Parameters:

Name Type Description Default

array

NDArray

Two-dimensional numpy array to be plotted, may be labelled or unlabelled data.

required

img_name

str

The image name from which the data is derived.

None

layer

int

The layer that is being plotted.

None

outdir

str | Path

Target output directory, will be created if it does not exist.

None

format

str

Image format for creating image. Default is png.

None

cmap

str

Colormap to plot as, defaults to black for binary images, viridis for heights. Labelled images are plotted as is.

None

Returns:

Type Description
tuple[Figure, Axes]

Matplotlib Figure and Axes.

plot_pores_by_layer

plot_pores_by_layer(
    pores_per_layer,
    img_name=None,
    outdir=None,
    format=None,
    log=False,
    grid=False,
)

Plot the layer v number of pores within it.

Parameters:

Name Type Description Default

pores_per_layer

list[int]

A list of the number of pores in each layer.

required

img_name

str

Image name.

None

outdir

str | Path

Output directory, if no None the image is saved there as <img_name>_pores_per_layer_[log].<format>.

None

format

str

Output file format as a string, defaults to png if not specified.

None

log

bool

Whether to plot with the logarithm (base10) of the number of pores.

False

grid

bool

Whether to include a grid on the plot.

False

Returns:

Type Description
tuple[Figure, Axes]

Returns a tuple of Matplotlib fig and ax.