plot_rates
plot_rates(rates, *, tmin=None, tmax=None, var="tgas", npoints=100, labels=None, palette=None, xlabel="Temperature (K)", ylabel=r"Rate coefficient $k$", xscale="log", yscale="log", shade=False, title="", fig=None, ax=None, grid=True, show=True, save=False, filename="rates.png")
Plots one or more rate coefficients on shared axes with a legend. Each curve is
coerced to (x, y, label) and drawn with a distinct line width (thinner curves
in front). Inputs are duck-typed and dispatched per item, so a single call may
mix reactions, expressions, and arrays.
Parameters
- rates : reaction-like, sympy.Basic, (x, y) tuple, or list of these
-
What to plot. Each item is one of:
- a reaction-like object (anything exposing
rate, and usuallytmin/tmax/get_latex): its rate is evaluated over its temperature range on a log grid; - a SymPy expression: evaluated over
[tmin, tmax](both required); - an
(x, y)pair of arrays: used verbatim.
- a reaction-like object (anything exposing
- tmin, tmax : float or None, optional
- Temperature range (K). For reactions, falls back to each reaction's own bounds, then to
2.73/1e6. Required for bare SymPy expressions. - var : str, optional
- Symbol name to substitute when evaluating reaction rates. Default
"tgas". - npoints : int, optional
- Number of log-spaced sample points. Default
100. - labels : list[str] or None, optional
- Legend labels aligned to
rates. Defaults to each reaction's LaTeX equation (orstr). - palette : list[str] or None, optional
- Colour-cycle override (e.g.
MUTED_PALETTEfor many curves). - xlabel, ylabel : str, optional
- Axis labels. Default
"Temperature (K)"andRate coefficient $k$. - xscale, yscale : str, optional
"log"(default) or"linear".- shade : bool or float, optional
- Shade the area under each curve. Default
False. - title : str, optional
- Plot title. Default
"". - fig, ax : matplotlib.figure.Figure / matplotlib.axes.Axes or None, optional
- Existing figure/axes to draw on. Created if
None. - grid, show, save, filename : optional
- Standard rendering controls.
filenamedefault"rates.png".
Returns
- tuple[matplotlib.figure.Figure, matplotlib.axes.Axes] or None
- The figure and axes, or
Nonewhen no input could be evaluated.
Note
Photo-reaction rates carry a symbolic radiation-density variable and cannot be evaluated as a function of temperature; such inputs are skipped with a warning.
Examples
from jaff.plotting import plot_rates
import sympy as sp
plot_rates(net.reactions[0]) # single reaction
plot_rates(list(net.reactions)) # overlay all, legend by equation
plot_rates([r1, r2], tmax=1e4, shade=True) # shared bounds + shading
t = sp.Symbol("tgas")
plot_rates([1e-10 * (t / 300) ** 0.5], tmin=10, tmax=1e4, labels=["my rate"])