rgbmovie#

named_arrays.plt.rgbmovie(*TWXY, C, axis_time, axis_wavelength, ax=None, norm=None, vmin=None, vmax=None, wavelength_norm=None, wavelength_min=None, wavelength_max=None, kwargs_pcolormesh=None, **kwargs_animation)#

A convenience function that calls pcolormovie() with the outputs from named_arrays.colorsynth.rgb() and returns an animation instance and a colorbar.

This allows us to plot 4D cubes, with the third dimension being represented by color, using a pcolormovie()-like interface.

Parameters:
Return type:

tuple[FuncAnimation, FunctionArray[Cartesian2dVectorArray, AbstractScalar]]

Examples

Plot a random, 4D cube.

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,
    w=11,
    x=16,
    y=16,
)

# Define a simple coordinate grid
t = na.linspace(0, 2, axis="t", num=shape["t"]) * u.s
w = na.linspace(-1, 1, axis="w", num=shape["w"]) * u.mm
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 array of values to plot
a = na.random.uniform(-1, 1, shape_random=shape)

# Plot the coordinates and values using rgbmovie()
astropy.visualization.quantity_support()
fig, ax = plt.subplots(
    ncols=2,
    gridspec_kw=dict(width_ratios=[.9, .1]),
    constrained_layout=True,
)
ani, colorbar = na.plt.rgbmovie(
    t, w, x, y,
    C=a,
    axis_time="t",
    axis_wavelength="w",
    ax=ax[0],
);
na.plt.pcolormesh(
    C=colorbar,
    axis_rgb="w",
    ax=ax[1],
)
ax[1].yaxis.tick_right()
ax[1].yaxis.set_label_position("right")
ani = ani.to_jshtml()
plt.close(fig)
IPython.display.HTML(ani)