Quick Plot#

class pybamm.QuickPlot(solutions, output_variables=None, labels=None, colors=None, linestyles=None, shading='auto', figsize=None, n_rows=None, time_unit=None, spatial_unit='um', variable_limits='fixed', n_t_linear=100)[source]#

Generates a quick plot of a subset of key outputs of the model so that the model outputs can be easily assessed.

Parameters:
  • solutions ((iter of) pybamm.Solution or pybamm.Simulation) – The numerical solution(s) for the model(s), or the simulation object(s) containing the solution(s).

  • output_variables (list of str, optional) – List of variables to plot

  • labels (list of str, optional) – Labels for the different models. Defaults to model names

  • colors (list of str, optional) – The colors to loop over when plotting. Defaults to None, in which case the default color loop defined by matplotlib style sheet or rcParams is used.

  • linestyles (list of str, optional) – The linestyles to loop over when plotting. Defaults to [“-”, “:”, “–”, “-.”]

  • shading (str, optional) – The shading to use for 2D plots. Defaults to “auto”.

  • figsize (tuple of floats, optional) – The size of the figure to make

  • n_rows (int, optional) – The number of rows to use. If None (default), floor(n // sqrt(n)) is used where n = len(output_variables) so that the plot is as square as possible

  • time_unit (str, optional) – Format for the time output (“hours”, “minutes”, or “seconds”)

  • spatial_unit (str, optional) – Format for the spatial axes (“m”, “mm”, or “um”)

  • variable_limits (str or dict of str, optional) – How to set the axis limits (for 0D or 1D variables) or colorbar limits (for 2D variables). Options are:

  • n_t_linear (int, optional) –

    The number of linearly spaced time points added to the t axis for each sub-solution. Note: this is only used if the solution has hermite interpolation enabled.

    • ”fixed” (default): keep all axes fixes so that all data is visible

    • ”tight”: make axes tight to plot at each time

    • dictionary: fine-grain control for each variable, can be either “fixed” or “tight” or a specific tuple (lower, upper).

create_gif(number_of_images=80, duration=0.1, output_filename='plot.gif')[source]#

Generates x plots over a time span of max_t - min_t and compiles them to create a GIF.

Parameters:
  • number_of_images (int, optional) – Number of images/plots to be compiled for a GIF.

  • duration (float, optional) – Duration of visibility of a single image/plot in the created GIF.

  • output_filename (str, optional) – Name of the generated GIF file.

dynamic_plot(show_plot=True, step=None)[source]#

Generate a dynamic plot with a slider to control the time.

Parameters:
  • step (float, optional) – For notebook mode, size of steps to allow in the slider. Defaults to 1/100th of the total time.

  • show_plot (bool, optional) – Whether to show the plots. Default is True. Set to False if you want to only display the plot after plt.show() has been called.

plot(t, dynamic=False)[source]#

Produces a quick plot with the internal states at time t.

Parameters:
  • t (float) – Dimensional time (in ‘time_units’) at which to plot.

  • dynamic (bool, optional) – Determine whether to allocate space for a slider at the bottom of the plot when generating a dynamic plot. If True, creates a dynamic plot with a slider.

reset_axis()[source]#

Reset the axis limits to the default values. These are calculated to fit around the minimum and maximum values of all the variables in each subplot

slider_update(t)[source]#

Update the plot in self.plot() with values at new time

pybamm.dynamic_plot(*args, **kwargs)[source]#

Creates a pybamm.QuickPlot object (with arguments ‘args’ and keyword arguments ‘kwargs’) and then calls pybamm.QuickPlot.dynamic_plot(). The key-word argument ‘show_plot’ is passed to the ‘dynamic_plot’ method, not the QuickPlot class.

Returns:

plot – The ‘QuickPlot’ object that was created

Return type:

pybamm.QuickPlot

class pybamm.QuickPlotAxes[source]#

Class to store axes for the QuickPlot

add(keys, axis)[source]#

Add axis

Parameters:
  • keys (iter) – Iterable of keys of variables being plotted on the axis

  • axis (matplotlib Axis object) – The axis object

by_variable(key)[source]#

Get axis by variable name