plots

Generate plots.

plots.process_xaxis_unit(zunit)[source]

Convert x-axis unit label to plotting-ready form and make multiplier.

Parameters:

zunit (str) – Unit in which distance is to be plotted on x axis.

Returns:

  • zunit (str) – Unit in which distance is to be plotted on x axis.

  • zmult (float) – Factor by which distance (x axis) will be multiplied before plotting.

plots.process_yaxis_unit(varname)[source]

Pre-process info to be used on y axis.

Convert y-axis variable name to plotting-ready form and make y-axis unit label and multiplier.

Parameters:
  • zunit (str) – Unit in which distance is to be plotted.

  • varname (str) – Name of variable to be plotted on y axis.

Returns:

  • varname (str) – Name of variable to be plotted on y axis.

  • varunit (float) – Unit of y-axis variable.

  • varmult (float) – Factor by which y-axis variable will be multiplied before plotting.

plots.plot_profile_single(z, var, varname, title, zunit='um')[source]

Plot variable as a function of distance.

Parameters:
  • z (1D array) – Positions to be used on x axis. Can be either node positions (size nz) or midpoint positions (size nz - 1) depending on the y-axis variable.

  • var (1D array or dict of 1D arrays) – Quantity to be plotted on y-axis.

  • varname (str) – Name of y-axis variable.

  • title (str) – Plot title.

  • zunit (str, optional) – x-axis unit. The default is ‘um’.

Returns:

fig, ax

Return type:

matplotlib figure and axis

plots.add_profile(z, var, varname, zunit='um', extra_legend=None)[source]

Add set of profiles to existing plot.

If extra_legend arg is provided, a legend entry is added with a black symbol, which applies to all added profiles.

Parameters:
  • z (1D array) – Positions to be used on x axis. Can be either node positions (size nz) or midpoint positions (size nz - 1) depending on the y-axis variable.

  • var (dict of 1D arrays) – Quantities to be added to y-axis.

  • varname (str) – Name of y-axis variable.

  • zunit (str, optional) – x-axis unit. The default is ‘um’.

  • extra_legend (str, optional) – Common legend to all added profiles. The default is None.

plots.plot_profile_quartet(result, title, suptitle, zunit='um', ylim=None, exclude_dep=True)[source]

Plot composition and flux profiles.

Produce a 2 x 2 grid of subplots with the following variables:

  • Atom fraction

  • Relative difference between simulated and equilibrium vacancy site fraction

  • Flux in the lattice-fixed frame

  • Volume fraction of pores.

Parameters:
  • result (results.UnitResult) – Simulation results at given time step.

  • title (str) – Axis title.

  • suptitle (str) – Plot title.

  • zunit (str, optional) – x-axis unit. The default is ‘um’.

  • ylim (dict, optional) – Lower and upper limits of the y-axis of the four subplots. Four keys are recognized: ‘x’, ‘y0’, ‘J’, ‘fp’. The values are to be given as a tuple or list of two floats. The default is None.

  • exclude_dep (bool, optional) – Exclude the dependent constituent from the atom fraction subplots. The default is True.

Returns:

  • fig (matplotlib.figure.Figure) – Figure.

  • axes (list of matplotlib.axes._subplots.AxesSubplot) – Axes.

  • lines (list of lists of matplotlib.lines.Line2D) – Lines.

class plots.StaticProfile(res, step, th, title)[source]

Bases: object

Static plot of composition and/or flux profile.

Variables:
  • res (results.UnitResult) – Simulation results at one time step.

  • step (int) – Time step.

  • th (float) – Time (h).

  • title (str) – Default plot title.

single(varname='x', title=None, plot_dep=False, **kwargs)[source]

Plot profile at given time step.

Call plots.plot_profile_single(). The plotted variable can be multivalued (dict) or univalued (1D array).

Parameters:
  • varname (str, optional) – Name of variable to be plotted. The default is x.

  • plot_dep (bool) – Whether to include dependent constituent in x and y plots.

  • kwargs – Optional arguments passed to plot_profile_single().

Returns:

fig, ax

Return type:

matplotlib figure and axis

Raises:

Exception – If variable is not recognized.

quartet(title=None, **kwargs)[source]

Plot composition and flux profiles at given time step.

Call plots.plot_profile_quartet(). Plot x, yVa, Jlat, fp.

Parameters:

kwargs – Optional arguments passed to plot_profile_quartet().

Returns:

fig, axes, lines

Return type:

matplotlib figure, axes and lines

plots.calculate_view_limits(results, varname)[source]

Compute y-axis limits adapted to results at all time steps.

Parameters:
  • results (dict of results.UnitStep) – Contains simulation results with time steps as keys.

  • varname (str) – Name of variable of interest.

Returns:

ylim – y-axis view limits for variable of interest.

Return type:

dict of lists

class plots.InteractivePlot(varname, comps, results, saved_times, saved_steps, title)[source]

Bases: object

Interactive plot of simulation results.

setup_plot(title, xlim, ylim)[source]

Make figure with empty lines.

Parameters:
  • title (str) – Figure title.

  • xlim (list of floats) – x-axis view limits.

  • ylim (dict of lists) – y-axis view limits.

Returns:

  • fig (matplotlib.figure.Figure) – Figure.

  • ax (matplotlib.axes._subplots.AxesSubplot) – Axis.

  • lines (list of matplotlib.lines.Line2D) – Lines.

on_scroll(event)[source]

Define callback used on scrolling.

update_slider(val)[source]

Set slider to given position (time step) and update the figure.

update()[source]

Update and draw the figure.

class plots.InteractivePlotQuartet(comps, results, saved_times, saved_steps, title)[source]

Bases: object

Interactive plot of composition and flux profiles.

The layout and quantities plotted are the same as in plot_profiles_and_fluxes().

setup_plot(title, xlim, ylim)[source]

Make figure with empty lines.

Parameters:
  • title (str) – Figure title.

  • xlim (list of floats) – x-axis view limits.

  • ylim (dict of lists) – y-axis view limits (see plot_profiles_and_fluxes() for keys).

Returns:

  • fig (matplotlib.figure.Figure) – Figure.

  • axes (list of matplotlib.axes._subplots.AxesSubplot) – Axes.

  • lines (list of lists of matplotlib.lines.Line2D) – Lines.

on_scroll(event)[source]

Define callback used on scrolling.

update_slider(val)[source]

Set slider to given position (time step) and update the figure.

update()[source]

Update and draw the figure.

plots.plot_mass_balance(results)[source]

Plot mass balance.

Parameters:

results (results.SimulationResults) – Simulation results.

Returns:

fig, ax

Return type:

matplotlib figure and axis