topostats.plottingfuncs#

Plotting data.

Attributes#

Classes#

Images

Plots image arrays.

Functions#

add_pixel_to_nm_to_plotting_config(→ dict)

Add the pixel to nanometre scaling factor to plotting configs.

dilate_binary_image(→ numpy.ndarray)

Dilate a supplied binary image a given number of times.

load_mplstyle(→ None)

Load the Matplotlibrc parameter file.

add_bounding_boxes_to_plot(→ None)

Add the bounding boxes to a plot.

set_n_ticks(→ None)

Set the number of ticks along the y and x axes and lets matplotlib assign the values.

Module Contents#

topostats.plottingfuncs.LOGGER#
topostats.plottingfuncs.add_pixel_to_nm_to_plotting_config(plotting_config: dict, pixel_to_nm_scaling: float) dict#

Add the pixel to nanometre scaling factor to plotting configs.

Ensures plots are in nanometres and not pixels.

Parameters:
  • plotting_config (dict) – TopoStats plotting configuration dictionary

  • pixel_to_nm_scaling (float) – Pixel to nanometre scaling factor for the image.

Returns:

plotting_config – Updated plotting config with the pixel to nanometre scaling factor applied to all the image configurations.

Return type:

dict

topostats.plottingfuncs.dilate_binary_image(binary_image: numpy.ndarray, dilation_iterations: int) numpy.ndarray#

Dilate a supplied binary image a given number of times.

Parameters:
  • binary_image (np.ndarray) – Binary image to be dilated

  • dilation_iterations (int) – Number of dilation iterations to be performed

Returns:

binary_image – Dilated binary image

Return type:

np.ndarray

topostats.plottingfuncs.load_mplstyle(style: str | pathlib.Path) None#

Load the Matplotlibrc parameter file.

Parameters:

style (str | Path) – Path to a Matplotlib Style file.

Returns:

Only loads the style file.

Return type:

None

class topostats.plottingfuncs.Images(data: numpy.array, output_dir: str | pathlib.Path, filename: str, style: str | pathlib.Path = None, pixel_to_nm_scaling: float = 1.0, masked_array: numpy.array = None, title: str = None, image_type: str = 'non-binary', image_set: str = 'core', core_set: bool = False, pixel_interpolation: str | None = None, cmap: str | None = None, mask_cmap: str = 'jet_r', region_properties: dict = None, zrange: list = None, colorbar: bool = True, axes: bool = True, num_ticks: list[int | None, int | None] = (None, None), save: bool = True, savefig_format: str | None = None, histogram_log_axis: bool = True, histogram_bins: int | None = None, savefig_dpi: str | float | None = None)#

Plots image arrays.

data#
output_dir#
filename#
pixel_to_nm_scaling#
masked_array#
title#
image_type#
image_set#
core_set#
interpolation#
cmap#
mask_cmap#
region_properties#
zrange#
colorbar#
axes#
num_ticks#
save#
savefig_format#
histogram_log_axis#
histogram_bins#
savefig_dpi#
plot_histogram_and_save()#

Plot and save a histogram of the height map.

Returns:

  • fig (plt.figure.Figure) – Matplotlib.pyplot figure object

  • ax (plt.axes._subplots.AxesSubplot) – Matplotlib.pyplot axes object

plot_and_save()#

Plot and save the images with savefig or imsave depending on config file parameters.

Returns:

  • fig (plt.figure.Figure) – Matplotlib.pyplot figure object

  • ax (plt.axes._subplots.AxesSubplot) – Matplotlib.pyplot axes object

save_figure()#

Save figures as plt.savefig objects.

Returns:

  • fig (plt.figure.Figure) – Matplotlib.pyplot figure object

  • ax (plt.axes._subplots.AxesSubplot) – Matplotlib.pyplot axes object

save_array_figure() None#

Save the image array as an image using plt.imsave().

topostats.plottingfuncs.add_bounding_boxes_to_plot(fig, ax, shape, region_properties: list, pixel_to_nm_scaling: float) None#

Add the bounding boxes to a plot.

Parameters:
  • fig (plt.figure.Figure) – Matplotlib.pyplot figure object

  • ax (plt.axes._subplots.AxesSubplot.) – Matplotlib.pyplot axes object

  • shape (tuple) – Tuple of the image-to-be-plot’s shape.

  • region_properties – Region properties to add bounding boxes from.

  • pixel_to_nm_scaling (float) – The scaling factor from px to nm.

Returns:

  • fig (plt.figure.Figure) – Matplotlib.pyplot figure object.

  • ax (plt.axes._subplots.AxesSubplot) – Matplotlib.pyplot axes object.

topostats.plottingfuncs.set_n_ticks(ax: matplotlib.pyplot.Axes.axes, n_xy: list[int | None, int | None]) None#

Set the number of ticks along the y and x axes and lets matplotlib assign the values.

Parameters:
  • ax (plt.Axes.axes) – The axes to add ticks to.

  • n_xy (list[int, int]) – The number of ticks.

Returns:

The axes with the new ticks.

Return type:

plt.Axes.axes