Residuals — model comparison at a glance¶
When comparing cosmological models, absolute power spectra span many orders of
magnitude and small differences are invisible on a log-log plot.
Residuals collapse that dynamic range: a flat line means perfect agreement, and
deviations stand out immediately.
Every cplots plot exposes two methods — residuals() for a standalone residual
panel and with_residuals() for a stacked two-panel figure with a shared x-axis.
Setup¶
Standalone residuals¶
residuals() returns a plain XYPlot — render it, overlay it, or pass it to
with_residuals() yourself.
Relative residuals¶
(y − y_ref) / y_ref — the default and most cosmologically natural choice.
Ratio residuals¶
y / y_ref — equivalent to relative + 1, preferred when you want to quote fractional deviations around unity rather than zero.
Two-panel stacked figure¶
with_residuals() combines the main spectrum and its residuals into a single
figure. The panels share an x-axis so zoom and pan stay in sync.
Selecting the reference by label instead of index makes the code self-documenting and robust to trace reordering.
External reference array¶
Pass a numpy array as reference to compare against a curve that is not part
of the plot — for example, an analytic approximation or a result from a
different code.
cplots interpolates the external reference onto each trace's x-grid (log-interpolation when the x-axis is logarithmic).