chemreac.util.plotting

This module collects convenience functions to create matplotlib plots of results.

chemreac.util.plotting.coloured_spy(A, cmap_name='coolwarm', log=False, symmetric_colorbar=False, **kwargs)[source]

Convenience function for using matplotlib to generate a spy plot for inspecting e.g. a jacobian matrix or its LU decomposition.

Parameters
A: 2D array

Array to inspect, populated e.g. by jacobian callback.

cmap_name: string (default: coolwarm)

name of matplotlib colormap to use, kwargs[“cmap”] overrides this.

log: bool or int

when True: LogNorm/SymLogNorm is used, when integer: SymlogNorm(10**log). Note that “norm” in kwargs override this.

symmetric_colorbar: bool or float

to make divergent colormaps pass through zero as intended. if float: max abolute value of colormap (linear)

Returns
Pair (tuple) of axes plotted to (spy, colorbar)

Note

colorbar does not play nicely with SymLogNorm why a custom colorbar axes is drawn.

chemreac.util.plotting.plot_C_vs_t_and_x(rd, tout, Cout, substance, ax=None, log10=False, **plot_kwargs)[source]

Plots 3D surface of concentration as function of time and x for a selected substance.

Parameters
rd: ReactionDiffusion
tout: 1D array of floats
Cout: concentration trajectories from solver
substance: int or string

index or name of substance

ax: Axes instance
log10: bool

Use log logarithmic (base 10) axis

**plot_kwargs:

passed onto plot_surface

Returns
Axes3D instance
chemreac.util.plotting.plot_C_vs_t_in_bin(rd, tout, Cout, bi=0, ax=None, labels=None, xscale='log', yscale='log', substances=None, ttlfmt=None, legend_kwargs=None, ls=None, c=None, xlabel=None, ylabel=None)[source]

Plots bin local concentration as function of time for selected substances.

Parameters
rd: ReactionDiffusion
tout: 1D array of floats
Cout: concentration trajectories from solver
bi: bin index
ax: Axes instance
labels: sequence of strings
xscale: matplotlib scale choice (e.g. ‘log’, ‘symlog’)
yscale: matplotlib scale choice (e.g. ‘log’, ‘symlog’)
substances: sequence of indies or names of substances
ttlfmt: string formatted with bin boundaries (set to empty to suppress)
legend_kwargs: dict

kwargs passed to matplotlib legend function, (default: {‘loc’: None, ‘prop’: {‘size’: 12}}), set to False to suppress legend.

ls: sequence of strings

linestyles

c: sequence of strings

colors

Returns
Axes instance
chemreac.util.plotting.plot_C_vs_x(rd, tout, Cout, substances, ti, ax=None, labels=None, xscale='log', yscale='log', basetitle='C(x)', ls=None, c=None)[source]

Plots concentration as function of x for selected substances at time index ‘ti’.

Parameters
rd: ReactionDiffusion
tout: 1D array of floats
Cout: concentration trajectories from solver
substances: sequence of indies or names of substances
ti: int

time index

ax: Axes instance
labels: sequence of strings
xscale: matplotlib scale choice (e.g. ‘linear’, ‘log’, ‘symlog’)
yscale: matplotlib scale choice (e.g. ‘linear’, ‘log’, ‘symlog’)
basetitle: string
Returns
Axes instance
chemreac.util.plotting.plot_fields(rd, ax=None, indices=None, rho=None)[source]

Convenience function to inspect fields in of ReactionDiffusion instance

Parameters
rd: ReactionDiffusion
ax: Axes instance or dict

if ax is a dict it is used as keyword arguments passed to matplotlib.pyplot.axes (default: None)

indices: sequence of integers

what field strengths sequences to plot

rho: float (optional)

density, with consistent unit. If passed doserate will be plotted instead.

chemreac.util.plotting.plot_jacobian(rd, tout, yout, substances, **kwargs)[source]

Plots time evolution of Jacobian values (useful when investigating numerical instabilities).

Parameters
rd: ReactionDiffusion

system at hand

tout: array_like

output time from integration

yout: array_like

output data from integration (differs from Cout for logy=True)

substances: iterable of int or string

indices or names of substances to plot jacobian values for

chemreac.util.plotting.plot_per_reaction_contribution(integr, substances, equilibria=None, field_yields=False, **kwargs)[source]

Plots contributions to concentration derivatives of selected substances from individual reactions.

Parameters
integr: Integration instance
substances: sequence of Substance instances
equilibria: set of tuples of reaction indices (optional)

When passed only net effect of equilibria reaction will be plotted

field_yields: bool (default: False)

If True contributions from g_values times field will be shown

**kwargs: kwargs passed on to _plot_analysis
Returns
list of matplotlib.axes.Axes instances
chemreac.util.plotting.plot_solver_linear_error(integration, Cref=0, ax=None, x=None, ti=slice(None, None, None), bi=0, si=0, plot_kwargs=None, fill_between_kwargs=None, scale_err=1.0, fill=True, **kwargs)[source]
Parameters
integration: chemreac.integrate.Integration

result from integration.

Cref: array or float

analytic solution to compare with

ax: Axes instance or dict

if ax is a dict it is used as key word arguments passed to matplotlib.pyplot.axes (default: None)

x: array

(optional) x-values, when None it is deduced to be either t or x (when ti or bi are slices repecitvely) (default: None)

ti: slice

time indices

bi: slice

bin indices

si: integer

specie index

plot_kwargs: dict

keyword arguments passed to matplotlib.pyplot.plot (default: None)

fill_between_kwargs: dict

keyword arguments passed to matplotlib.pyplot.fill_between (default: None)

scale_err: float

value with which errors are scaled. (default: 1.0)

fill: bool

whether or not to fill error span

**kwargs

common keyword arguments of plot_kwargs and fill_between_kwargs, e.g. ‘color’, (default: None).

chemreac.util.plotting.plot_solver_linear_excess_error(integration, Cref, ax=None, x=None, ti=slice(None, None, None), bi=0, si=0, **kwargs)[source]

Plots the excess error commited by the intergrator, divided by the span of the tolerances (atol + rtol*|y_i|).

Parameters
integration: chemreac.integrate.Integration

result from integration.

Cref: array or float

analytic solution to compare with

ax: Axes instance or dict

if ax is a dict it is used as **kwargs passed to matplotlib.pyplot.axes (default: None)

x: array

(optional) x-values, when None it is deduced to be either t or x (when ti or bi are slices repecitvely) (default: None)

ti: slice

time indices

bi: slice

bin indices

si: integer

specie index

plot_kwargs: dict

keyword arguments passed to matplotlib.pyplot.plot (default: None)

fill_between_kwargs: dict

keyword arguments passed to matplotlib.pyplot.fill_between (default: None)

scale_err: float

value with which errors are scaled. (default: 1.0)

fill: bool

whether or not to fill error span

**kwargs:

common keyword arguments of plot_kwargs and fill_between_kwargs, e.g. ‘color’, (default: None).

chemreac.util.plotting.save_and_or_show_plot(show=None, savefig='None', **kwargs)[source]

Save and/or show current matplotlib figure

Parameters
show: bool or None

Show plot, when None only show when savefig is not used default: None

savefig: string

path to output file of figure. If extension is html, mpld3 will be used to generate a d3 backed html output.

**kwargs:

keyword arguments passed on to matplotlib.pyplot.savefig