4.8.2 pde.visualization.plotting module

Functions and classes for plotting simulation data.

ScalarFieldPlot

Class managing compound plots of scalar fields.

plot_magnitudes

Plot spatially averaged quantities as a function of time.

plot_kymograph

Plots a single kymograph from stored data.

plot_kymographs

Plots kymographs for all fields stored in storage

plot_interactive

plots stored data interactively using the napari viewer

class ScalarFieldPlot(fields, quantities=None, scale='automatic', fig=None, title=None, tight=False, show=True)[source]

Bases: object

Class managing compound plots of scalar fields.

Parameters:
  • fields (FieldBase) – Collection of fields

  • quantities – A 2d list of quantities that are shown in a rectangular arrangement. If quantities is a simple list, the panels will be rendered as a single row. Each panel is defined by a dictionary, where the mandatory item ‘source’ defines what is being shown. Here, an integer specifies the component that is extracted from the field while a function is evaluate with the full state as an input and the result is shown. Additional items in the dictionary can be ‘title’ (setting the title of the panel), ‘scale’ (defining the color range shown; these are typically two numbers defining the lower and upper bound, but if only one is given the range [0, scale] is assumed), and ‘cmap’ (defining the colormap being used).

  • scale (str, float, tuple of float) – Flag determining how the range of the color scale is determined. In the simplest case a tuple of numbers marks the lower and upper end of the scalar values that will be shown. If only a single number is supplied, the range starts at zero and ends at the given number. Additionally, the special value ‘automatic’ determines the range from the range of scalar values.

  • ( (fig) – class:matplotlib.figure.Figure): Figure to be used for plotting. If `None, a new figure is created.

  • title (str) – Title of the plot.

  • tight (bool) – Whether to call matplotlib.pyplot.tight_layout(). This affects the layout of all plot elements.

  • show (bool) – Flag determining whether to show a plot. If False, the plot is kept in the background, which can be useful if it only needs to be written to a file.

classmethod from_storage(storage, quantities=None, scale='automatic', tight=False, show=True)[source]

Create ScalarFieldPlot from storage.

Parameters:
  • storage (StorageBase) – Instance of the storage class that contains the data

  • quantities – A 2d list of quantities that are shown in a rectangular arrangement. If quantities is a simple list, the panels will be rendered as a single row. Each panel is defined by a dictionary, where the mandatory item ‘source’ defines what is being shown. Here, an integer specifies the component that is extracted from the field while a function is evaluate with the full state as an input and the result is shown. Additional items in the dictionary can be ‘title’ (setting the title of the panel), ‘scale’ (defining the color range shown; these are typically two numbers defining the lower and upper bound, but if only one is given the range [0, scale] is assumed), and ‘cmap’ (defining the colormap being used).

  • scale (str, float, tuple of float) – Flag determining how the range of the color scale is determined. In the simplest case a tuple of numbers marks the lower and upper end of the scalar values that will be shown. If only a single number is supplied, the range starts at zero and ends at the given number. Additionally, the special value ‘automatic’ determines the range from the range of scalar values.

  • tight (bool) – Whether to call matplotlib.pyplot.tight_layout(). This affects the layout of all plot elements.

  • show (bool) – Flag determining whether to show a plot. If False, the plot is kept in the background.

Returns:

ScalarFieldPlot

Return type:

ScalarFieldPlot

make_movie(storage, filename, progress=True)[source]

Make a movie from the data stored in storage.

Parameters:
  • storage (StorageBase) – The storage instance that contains all the data for the movie

  • filename (str) – The filename to which the movie is written. The extension determines the format used.

  • progress (bool) – Flag determining whether the progress of making the movie is shown.

Return type:

None

savefig(path, **kwargs)[source]

Save plot to file.

Parameters:
  • path (str) – The path to the file where the image is written. The file extension determines the image format

  • **kwargs – Additional arguments are forwarded to matplotlib.figure.Figure.savefig().

update(fields, title=None)[source]

Update the plot with the given fields.

Parameters:
  • fields (FieldBase) – The field or field collection of which the defined quantities are shown.

  • title (str, optional) – The title of this view. If None, the current title is not changed.

Return type:

None

extract_field(fields, source=None, check_rank=None)[source]

Extracts a single field from a possible collection.

Parameters:
  • fields (FieldBase) – The field from which data is extracted

  • source (int or callable, optional) – Determines how a field is extracted from fields. If None, fields is passed as is, assuming it is already a scalar field. This works for the simple, standard case where only a single ScalarField is treated. Alternatively, source can be an integer, indicating which field is extracted from an instance of FieldCollection. Lastly, source can be a function that takes fields as an argument and returns the desired field.

  • check_rank (int, optional) – Can be given to check whether the extracted field has the correct rank (0 = ScalarField, 1 = VectorField, …).

Returns:

The extracted field

Return type:

DataFieldBase

plot_interactive(storage, time_scaling='exact', viewer_args=None, **kwargs)[source]

plots stored data interactively using the napari viewer

Parameters:
  • storage (StorageBase) – The storage instance that contains all the data

  • time_scaling (str) – Defines how the time axis is scaled. Possible options are “exact” (the actual time points are used), or “scaled” (the axis is scaled so that it has similar dimension to the spatial axes). Note that the spatial axes will never be scaled.

  • viewer_args (dict) – Arguments passed to napari.viewer.Viewer to affect the viewer.

  • **kwargs – Extra arguments passed to the plotting function

plot_kymograph(storage, field_index=None, scalar='auto', extract='auto', colorbar=True, transpose=False, *args, title=None, filename=None, action='auto', ax_style=None, fig_style=None, ax=None, **kwargs)[source]

Plots a single kymograph from stored data.

The kymograph shows line data stacked along time. Consequently, the resulting image shows space along the horizontal axis and time along the vertical axis.

Parameters:
  • storage (StorageBase) – The storage instance that contains all the data

  • field_index (int) – An index to choose a single field out of many in a collection stored in storage. This option should not be used if only a single field is stored in a collection.

  • scalar (str) – The method for extracting scalars as described in DataFieldBase.to_scalar().

  • extract (str) – The method used for extracting the line data. See the docstring of the grid method get_line_data to find supported values.

  • colorbar (bool) – Whether to show a colorbar or not

  • transpose (bool) – Determines whether the transpose of the data should is plotted

  • Title (str) – Title of the plot. If omitted, the title might be chosen automatically.

  • filename (str, optional) – If given, the plot is written to the specified file.

  • action (str) – Decides what to do with the final figure. If the argument is set to show, matplotlib.pyplot.show() will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.

  • ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.

  • fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.

  • ax (matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.

  • **kwargs – Additional keyword arguments are passed to matplotlib.pyplot.imshow().

  • title (str | None)

Returns:

The reference to the plot

Return type:

PlotReference

plot_kymographs(storage, scalar='auto', extract='auto', colorbar=True, transpose=False, resize_fig=True, *args, title=None, constrained_layout=True, filename=None, action='auto', fig_style=None, fig=None, **kwargs)[source]

Plots kymographs for all fields stored in storage

The kymograph shows line data stacked along time. Consequently, the resulting image shows space along the horizontal axis and time along the vertical axis.

Parameters:
  • storage (StorageBase) – The storage instance that contains all the data

  • scalar (str) – The method for extracting scalars as described in DataFieldBase.to_scalar().

  • extract (str) – The method used for extracting the line data. See the docstring of the grid method get_line_data to find supported values.

  • colorbar (bool) – Whether to show a colorbar or not

  • transpose (bool) – Determines whether the transpose of the data should is plotted

  • resize_fig (bool) – Whether to resize the figure to adjust to the number of panels

  • title (str) – Title of the plot. If omitted, the title might be chosen automatically. This is shown above all panels.

  • constrained_layout (bool) – Whether to use constrained_layout in matplotlib.pyplot.figure() call to create a figure. This affects the layout of all plot elements. Generally, spacing might be better with this flag enabled, but it can also lead to problems when plotting multiple plots successively, e.g., when creating a movie.

  • filename (str, optional) – If given, the figure is written to the specified file.

  • action (str) – Decides what to do with the final figure. If the argument is set to show, matplotlib.pyplot.show() will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.

  • fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.

  • fig (matplotlib.figures.Figure) – Figure that is used for plotting. If omitted, a new figure is created.

  • **kwargs – Additional keyword arguments are passed to the calls to matplotlib.pyplot.imshow().

Returns:

The references to all plots

Return type:

list of PlotReference

plot_magnitudes(storage, quantities=None, *args, title=None, filename=None, action='auto', ax_style=None, fig_style=None, ax=None, **kwargs)[source]

Plot spatially averaged quantities as a function of time.

For scalar fields, the default is to plot the average value while the averaged norm is plotted for vector fields.

Parameters:
  • storage (StorageBase) – Instance of StorageBase that contains the simulation data that will be plotted

  • quantities – A 2d list of quantities that are shown in a rectangular arrangement. If quantities is a simple list, the panels will be rendered as a single row. Each panel is defined by a dictionary, where the mandatory item ‘source’ defines what is being shown. Here, an integer specifies the component that is extracted from the field while a function is evaluate with the full state as an input and the result is shown. Additional items in the dictionary can be ‘title’ (setting the title of the panel), ‘scale’ (defining the color range shown; these are typically two numbers defining the lower and upper bound, but if only one is given the range [0, scale] is assumed), and ‘cmap’ (defining the colormap being used).

  • Title (str) – Title of the plot. If omitted, the title might be chosen automatically.

  • filename (str, optional) – If given, the plot is written to the specified file.

  • action (str) – Decides what to do with the final figure. If the argument is set to show, matplotlib.pyplot.show() will be called to show the plot. If the value is none, the figure will be created, but not necessarily shown. The value close closes the figure, after saving it to a file when filename is given. The default value auto implies that the plot is shown if it is not a nested plot call.

  • ax_style (dict) – Dictionary with properties that will be changed on the axis after the plot has been drawn by calling matplotlib.pyplot.setp(). A special item i this dictionary is use_offset, which is flag that can be used to control whether offset are shown along the axes of the plot.

  • fig_style (dict) – Dictionary with properties that will be changed on the figure after the plot has been drawn by calling matplotlib.pyplot.setp(). For instance, using fig_style={‘dpi’: 200} increases the resolution of the figure.

  • ax (matplotlib.axes.Axes) – Figure axes to be used for plotting. The special value “create” creates a new figure, while “reuse” attempts to reuse an existing figure, which is the default.

  • **kwargs – All remaining parameters are forwarded to the ax.plot method

  • title (str | None)

Returns:

The reference to the plot

Return type:

PlotReference