rgbmesh#

named_arrays.plt.rgbmesh(*WXY, C, axis_wavelength, ax=None, norm=None, vmin=None, vmax=None, wavelength_norm=None, wavelength_min=None, wavelength_max=None, **kwargs)#

A convenience function that calls pcolormesh() with the outputs from named_arrays.colorsynth.rgb() and returns a colorbar.

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

Parameters:
Return type:

FunctionArray[Cartesian2dVectorArray, AbstractScalar]

Examples

Plot a random, 3D cube.

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

# Define a random 3d cube
a = na.random.uniform(
    low=0 * u.photon,
    high=1000 * u.photon,
    shape_random=dict(x=16, y=16, wavelength=11),
)

# Define wavelength coordinates
wavelength = na.linspace(
    start=100 * u.AA,
    stop=200 * u.AA,
    axis="wavelength",
    num=a.shape["wavelength"],
)

# Define spatial coordinates
x = na.linspace(-1, 1, axis="x", num=a.shape["x"]) * u.mm
y = na.linspace(-1, 1, axis="y", num=a.shape["y"]) * u.mm

# Plot the colorbar
with astropy.visualization.quantity_support():
    fig, axs = plt.subplots(
        ncols=2,
        gridspec_kw=dict(width_ratios=[.9,.1]),
        constrained_layout=True,
    )
    colorbar = na.plt.rgbmesh(
        wavelength, x, y,
        C=a,
        axis_wavelength="wavelength",
        ax=axs[0],
    );
    na.plt.pcolormesh(
        C=colorbar,
        axis_rgb="wavelength",
        ax=axs[1],
    )
    axs[1].yaxis.tick_right()
    axs[1].yaxis.set_label_position("right")
../_images/named_arrays.plt.rgbmesh_0_0.png