🌈 Visualizations¶
chromatic
provides built-in visualizations for 🌈 datasets, trying to make it easier to look closely at complicated data and to facilitate standardized comparisons across different analyses.
from chromatic import SimulatedRainbow, version
from chromatic import plt, np, u
version()
'0.4.12'
We'll demonstrate some of the standard visualizations by generating a simulated rainbow with a cute wavelength-dependent transit signal injected into it.
s = SimulatedRainbow(dw=0.1 * u.micron, dt=4 * u.minute)
# inject an interesting transit signal
theta = np.linspace(0, 2 * np.pi, s.nwave)
planet_radius = np.sin(theta) * 0.05 + 0.2
r = s.inject_transit(planet_radius=planet_radius).inject_noise()
🌈.imshow()¶
Display the flux as an image, with each pixel representing the flux for a particular time and wavelength.
r.imshow();
There are a few options you might want to change.
r.imshow(cmap="gray", colorbar=False, w_unit="nm", t_unit="minute");
Or, you might want to plot a different quantity instead.
r.imshow(quantity="model");
.imshow
is often a good way to quickly display Rainbow
objects with wavelengths and times that are approximately uniformly spaced, either linearly or logarithmically. .pcolormesh
and .scatter
offer more flexibility for less uniform grids.
🌈.imshow_interact()¶
Display the flux as an image on the left, with the ability to drag and select which wavelengths you would like to appear in the light curve plot on the right.
r.imshow_interact();
Like imshow()
, there are options you might like to change (see Vega documentation for color schemes):
r.imshow_interact(cmap="magma", t_unit="h", w_unit="nm", ylim=[0.93, 1.01])
🌈.pcolormesh()¶
Display the flux as an image, with each pixel representing the flux for a particular time and wavelength, but using plt.pcolormesh
which allows pixels to stretch and squeeze based on the actual locations of their edges. Use .imshow()
if you want wavelength/time bins to appear with the uniform sizes; use .pcolormesh()
if you want to allow them to transform with the axes or non-uniform edges. It accepts most of the same options as .imshow()
.
r.pcolormesh();
r.pcolormesh()
plt.yscale("log")
.pcolormesh
is often a good way to quickly display Rainbow
objects with wavelengths and times that are smoothly varying but not necessarily exactly linearly or logarithmically spaced. .imshow
is faster for uniform grids, and .scatter
offer more flexibility for less uniform grids.
🌈.scatter()¶
Display the flux as a sparesely populated image, with each pixel representing the flux for a particular time and wavelength, using plt.scatter
to paint fluxes only where valid wavelength and time points exist. It accepts most of the same options as .imshow()
.
r.scatter()
🌈🤖 Times are linearly spaced, and wavelengths are linearly spaced. It's likely that `.imshow` or `.pcolormesh` are better ways to display this Rainbow.
.scatter
is often a good way to quickly display Rainbow
objects with wavelengths and times that are sparse or extremely non-uniform. .imshow
and .pcolormesh
will be faster and may look more professional for smooth, contiguous wavelength and time grids.
🌈.plot()¶
Display the flux by plotting a sequence of light curves for different wavelengths, with each curve representing the flux for a particular wavelength.
r.plot();
Eep! Since it plots an individual light curve for each wavelength, plotting lots of wavelengths at once will cause things to overlap and blend together. You might want to bin your rainbow before plotting it.
r.bin(R=3).plot();
There are a few options you might want to change.
r.bin(R=3).plot(
cmap="copper",
w_unit="nm",
t_unit="minute",
plotkw=dict(marker="s", markersize=2, linewidth=0),
textkw=dict(color="black", fontweight="bold"),
)
<Axes: xlabel='Time ($\\mathrm{min}$)', ylabel='Relative Flux (+ offsets)'>
This visualization returns an ax
object, which is the Axes where the plot was generated. You can feed that ax
into another plot command to overplot on top.
ax = r.bin(R=3).plot(
errorbar=False, plotkw=dict(alpha=0.2, markeredgecolor="none", linewidth=0)
)
r.bin(R=3, dt=15 * u.minute).plot(ax=ax);
🌈.animate_lightcurves()¶
Display the flux by animating a sequence of light curve plots, flipping through different wavelengths.
r.animate_lightcurves();
<IPython.core.display.Image object>
🌈.animate_spectra()¶
Display the flux by animating a sequence of spectrum plots, flipping through different times.
r.animate_spectra();
<IPython.core.display.Image object>
🌈.imshow_quantities()¶
Visualize all the imshow
-able quantities (things with same shape as flux
).
r.imshow_quantities(maxcol=4);
🌈.plot_quantities()¶
Plot quantities that can be expressed as time series or as spectra (things with same shape as time
or wavelength
).
r.plot_quantities(xaxis="time");
r.plot_quantities(xaxis="wavelength");
How do we do more with these plots?¶
Whatever plots you make, you can continue to call additional plt
commands after the plot has been generated. For example, you could add a title with plt.title()
or save the figure with plt.savefig(filename)
.
What's next?¶
To find other visualization options for your 🌈 object, run the .help()
and try things out! If you would like another kind of a visualization that doesn't already exist, please submit an Issue to discuss it.