Skip to content

Plotting

This module provides different plotting utilities that are commonly used in ML context such as plotting a grid of images or show a single image.

get_grid(n, nrows=None, ncols=None, title=None, weight='bold', size=14, **kwargs)

Return a grid of n axes, rows by cols. nrows and ncols are mutually exclusive. This means you only need to pass one of them and the other will be inferred.

Parameters:

Name Type Description Default
n int

Number of axes.

required
nrows int

Number of rows, default=int(math.sqrt(n)).

None
ncols int

Number of columns, default=ceil(n/rows).

None
title str

Title of the Figure.

None
weight str

Title font weight.

'bold'
size int

Title font size.

14

Returns:

Name Type Description
fig Figure

Top level container for all axes.

ax array of Axes

Array of axes.

show_image(image, ax=None, figsize=None, title=None, noframe=True, **kwargs)

Show a PIL or PyTorch image on ax.

Parameters:

Name Type Description Default
image PIL image or array-like

Image data.

required
ax Axes

Axes to plot the image on.

None
figsize tuple

Width, height in inches of the returned Figure

None
title str

Title of the image

None
noframe bool

Whether to remove axis from the plotted image.

True

Returns:

Name Type Description
ax AxesImage

Plotted image on ax.

show_images(images, nrows=None, ncols=None, titles=None, **kwargs)

Show all images as subplots with nrows x ncols using titles.

Parameters:

Name Type Description Default
images list or array - like

List of images to show.

required
nrows int

Number of rows in the grid.

None
ncols int

Number of columns in the grid.

None
titles list

List of titles for each image.

None

subplots(nrows=1, ncols=1, figsize=None, imsize=3, suptitle=None, **kwargs)

A figure and set of subplots to display images of imsize inches.

Parameters:

Name Type Description Default
nrows int

Number of rows in returned axes grid.

1
ncols int

Number of columns in returned axes grid.

1
figsize tuple

Width, height in inches of the returned Figure.

None
imsize int

Size (in inches) of images that will be displayed in the returned figure.

3
suptitle str

Title of the Figure.

None

Returns:

Name Type Description
fig Figure

Top level container for all axes.

ax array of Axes

Array of axes.