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: FieldBase, quantities=None, scale: Union[str, float, Tuple[float, float]] = 'automatic', fig=None, title: str = None, tight: bool = False, show: bool = 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: StorageBase, quantities=None, scale: Union[str, float, Tuple[float, float]] = 'automatic', tight: bool = False, show: bool = True) ScalarFieldPlot[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

make_movie(storage: StorageBase, filename: str, progress: bool = True) None[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.

savefig(path: str, **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: FieldBase, title: str = None) None[source]

update the plot with the given fields

Parameters
  • fields – 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.

extract_field(fields: FieldBase, source: Union[None, int, Callable] = None, check_rank: int = None) DataFieldBase[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: StorageBase, time_scaling: str = 'exact', viewer_args: dict = 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: StorageBase, field_index: int = None, scalar: str = 'auto', extract: str = 'auto', colorbar: bool = True, transpose: bool = False, *args, title: str = None, filename: str = None, action: str = 'auto', ax_style: dict = None, fig_style: dict = None, ax=None, **kwargs) PlotReference[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 in 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().

Returns

The reference to the plot

Return type

PlotReference

plot_kymographs(storage: StorageBase, scalar: str = 'auto', extract: str = 'auto', colorbar: bool = True, transpose: bool = False, resize_fig: bool = True, *args, title: str = None, constrained_layout: bool = True, filename: str = None, action: str = 'auto', fig_style: dict = None, fig=None, **kwargs) List[PlotReference][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: StorageBase, quantities=None, *args, title: str = None, filename: str = None, action: str = 'auto', ax_style: dict = None, fig_style: dict = None, ax=None, **kwargs) PlotReference[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 – 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 in 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

Returns

The reference to the plot

Return type

PlotReference