colorbar#
- colorsynth.colorbar(spd, wavelength=None, axis=-1, axis_intensity=0, axis_wavelength=1, spd_min=None, spd_max=None, spd_norm=None, wavelength_min=None, wavelength_max=None, wavelength_norm=None, squeeze=True)[source]#
Calculate the colorbar corresponding to calling
rgb()with these same arguments.The return value from this function is designed to be used directly by
matplotlib.pyplot.pcolormesh().- Parameters:
spd (ndarray) – a spectral power distribution to be converted into a RGB array
wavelength (None | Quantity) – The wavelength array corresponding to the spectral power distribution. If
None, the wavelength is assumed to be evenly sampled across the human visible color range.axis (int) – The logical axis corresponding to changing wavelength, or the axis along which to integrate the spectral power distribution
axis_intensity (int) – The index of new logical axis in the result which corresponds to changing spectral radiance.
axis_wavelength (int) – The index of a new logical axis in the result which corresponds to changing wavelength.
spd_min (None | ndarray) – the value of the spectral power distribution representing minimum intensity.
spd_max (None | ndarray) – the value of the spectral power distribution representing minimum intensity.
spd_norm (None | Callable[[ndarray], ndarray]) – an optional function to transform the spectral power distribution values before mapping to RGB
wavelength_min (None | Quantity) – the wavelength value that is mapped to the minimum wavelength of the human visible color range, 380 nm.
wavelength_max (None | Quantity) – the wavelength value that is mapped to the maximum wavelength of the human visible color range, 700 nm
wavelength_norm (None | Callable[[Quantity], Quantity]) – an optional function to transform the wavelength values before they are mapped into the human visible color range.
squeeze (bool) – A boolean flag indicating whether to remove singleton dimensions from the result. If you’re just making a single colorbar, this should be
True(the default) somatplotlib.pyplot.pcolormesh()will work correctly. If you’re making a stack of colorbars, you might want to set this toFalseso that you don’t lose track of axis meanings.
- Return type:
Examples
Plot the colorbar corresponding to a random, 3D cube.
import numpy as np import matplotlib.pyplot as plt import astropy.units as u import astropy.visualization import colorsynth # Define a random 3d cube a = np.random.uniform( low=0, high=1000, size=(16, 16, 11), ) * u.photon # Define wavelength axis wavelength = np.linspace( start=100 * u.AA, stop=200 * u.AA, num=a.shape[~0], ) # Compute the colorbar corresponding to the random 3d cube. colorbar = colorsynth.colorbar( spd=a, wavelength=wavelength, axis=~0, ) # Plot the colorbar with astropy.visualization.quantity_support(): fig, ax = plt.subplots() plt.pcolormesh(*colorbar)