imshow#

named_arrays.plt.imshow(X, *, axis_x, axis_y, axis_rgb=None, ax=None, cmap=None, norm=None, aspect=None, alpha=None, vmin=None, vmax=None, extent=None, **kwargs)#

A thin wrappper around matplotlib.pyplot.imshow() for named arrays.

Parameters:
Return type:

AbstractArray

Examples

Plot a random 2d array.

import numpy as np
import matplotlib.pyplot as plt
import named_arrays as na

# Define the horizontal and vertical axis names of the image
axis_x = "x"
axis_y = "y"

# Define a random dummy array to plot
a = na.random.uniform(
    low=0,
    high=1,
    shape_random={axis_x: 16, axis_y: 16},
)

# Create the plot axes
fig, ax = plt.subplots()

# Plot the dummy array
na.plt.imshow(
    a,
    axis_x=axis_x,
    axis_y=axis_y,
    ax=ax,
    extent=na.ScalarArray(
        ndarray=np.array([0, 1, 0, 1]),
        axes=f"{axis_x},{axis_y}",
    ),
);
../_images/named_arrays.plt.imshow_0_0.png

Plot a grid of 2d dummy arrays

import numpy as np
import matplotlib.pyplot as plt
import named_arrays as na

# Define the horizontal and vertical axis names of the plot
axis_x = "x"
axis_y = "y"

# Define the row and column axis names of the plot
axis_rows = "row"
axis_cols = "col"

# Define the number of rows and columns of the plot
num_rows = 2
num_cols = 3

# Define a random dummy array to plot
a = na.random.uniform(
    low=0,
    high=1,
    shape_random={
        axis_rows: num_rows,
        axis_cols: num_cols,
        axis_x: 16,
        axis_y: 16,
    }
)

# Define the array of matplotlib axes
fig, axs = na.plt.subplots(
    axis_rows=axis_rows,
    nrows=num_rows,
    axis_cols=axis_cols,
    ncols=num_cols,
    sharex=True,
    sharey=True,
    constrained_layout=True,
)

# Plot the dummy arrays
na.plt.imshow(
    a,
    axis_x=axis_x,
    axis_y=axis_y,
    ax=axs,
    extent=na.ScalarArray(
        ndarray=np.array([0, 1, 0, 1]),
        axes=f"{axis_x},{axis_y}",
    ),
);
../_images/named_arrays.plt.imshow_1_0.png