pcolormovie#

named_arrays.plt.pcolormovie(*TXY, C, axis_time, axis_rgb=None, ax=None, components=None, cmap=None, norm=None, vmin=None, vmax=None, kwargs_pcolormesh=None, kwargs_animation=None)#

Animate a sequence of images using matplotlib.animation.FuncAnimation and repeated calls to pcolormesh().

Parameters:
  • TXY (AbstractArray) – The coordinates of the mesh, including the temporal coordinate. If C is a scalar, TXY can either be three scalars or one scalar and one vector. If C is a function, TXY is not specified. If XY is not specified as two scalars, the components must be given, see below.

  • C (AbstractArray) – The mesh data.

  • axis_time (str) – The logical axis corresponding to the different frames in the animation.

  • axis_rgb (None | str) – The optional logical axis along which the RGB color channels are distributed.

  • ax (None | Axes | AbstractArray) – The instances of matplotlib.axes.Axes to use. If None, calls matplotlib.pyplot.gca() to get the current axes. If an instance of named_arrays.ScalarArray, ax.shape should be a subset of the broadcasted shape of *args.

  • components (None | tuple[str, str]) – If XY is not specified as two scalars, this parameter should be a tuple of two strings, specifying the vector components of XY to use as the horizontal and vertical components of the mesh.

  • cmap (None | str | Colormap | AbstractArray) – The colormap used to map scalar data to colors.

  • norm (None | str | Normalize) – The normalization method used to scale data into the range [0, 1] before mapping to colors.

  • vmin (None | int | float | complex | ndarray | Quantity | AbstractArray) – The minimum value of the data range.

  • vmax (None | int | float | complex | ndarray | Quantity | AbstractArray) – The maximum value of the data range.

  • kwargs_pcolormesh (None | dict[str, Any]) – Additional keyword arguments accepted by pcolormesh().

  • kwargs_animation (None | dict[str, Any]) – Additional keyword arguments accepted by matplotlib.animation.FuncAnimation.

Return type:

FuncAnimation

Examples

Plot a random 2D mesh

import matplotlib.pyplot as plt
import IPython.display
import astropy.units as u
import astropy.visualization
import named_arrays as na

# Define the size of the grid
shape = dict(
    t=3,
    x=16,
    y=16,
)

# Define a simple coordinate grid
t = na.linspace(-1, 1, axis="t", num=shape["t"]) * u.s
x = na.linspace(-2, 2, axis="x", num=shape["x"]) * u.mm
y = na.linspace(-1, 1, axis="y", num=shape["y"]) * u.mm

# Define a random 2D array of values to plot
a = na.random.uniform(-1, 1, shape_random=shape)

# Plot the coordinates and values using pcolormesh
astropy.visualization.quantity_support()
fig, ax = plt.subplots(constrained_layout=True)
ani = na.plt.pcolormovie(t, x, y, C=a, axis_time="t", ax=ax);
plt.close(fig)
IPython.display.HTML(ani.to_jshtml())

Plot a grid of random 2D meshes

import IPython.display
import astropy.units as u
import astropy.visualization
import named_arrays as na

# Define the size of the grid
shape = dict(
    t=3,
    row=2,
    col=3,
    x=16,
    y=16,
)

# Define a simple coordinate grid
t = na.linspace(-1, 1, axis="t", num=shape["t"]) * u.s
x = na.linspace(-2, 2, axis="x", num=shape["x"]) * u.mm
y = na.linspace(-1, 1, axis="y", num=shape["y"]) * u.mm

# Define a random 2D array of values to plot
a = na.random.uniform(-1, 1, shape_random=shape)

# Plot the coordinates and values using pcolormesh
astropy.visualization.quantity_support()
fig, ax = na.plt.subplots(
    axis_rows="row",
    axis_cols="col",
    nrows=shape["row"],
    ncols=shape["col"],
    sharex=True,
    sharey=True,
    constrained_layout=True,
)
ani = na.plt.pcolormovie(t, x, y, C=a, axis_time="t", ax=ax);
plt.close(fig)
IPython.display.HTML(ani.to_jshtml())