pyoomph.output.plotting module

class pyoomph.output.plotting.BasePlotter(problem, eigenvector=None, eigenmode='abs')[source]

Bases: object

A generic class for plotting of problems. This class is not meant to be used directly, but to be inherited by a specific plotter class.

define_plot()[source]

This functions must be implemented by the derived class to specify what should be plotted.

eigenmode: Literal['abs', 'real', 'imag', 'merge', 'angle']

The mode to plot eigenvectors, e.g. "abs" for the absolute value, "real" for the real part, etc.

eigenvector

The eigenvector to plot (given by an index). If None, it will plot the normal solution.

get_eigenvalue(problem_name='')[source]

When plotting eigenfunctions, it will return the eigenvalue of the current eigenvector. When plotting normal solutions, it is None.

Return type:

Optional[complex]

get_problem(problem_name='')[source]

Returns the problem on which we want to plot. Useful to access the properties of the problem, e.g. sizes.

class pyoomph.output.plotting.MatplotLibArrowKey(plotter)[source]

Bases: MatplotLibOverlayBase

An arrow key to be used in plots. Create it with MatplotlibPlotter.add_arrow_key().

class pyoomph.output.plotting.MatplotLibColorbar(plotter)[source]

Bases: MatplotLibOverlayBase

A color bar to be used in plots. Create it with MatplotlibPlotter.add_colorbar().

Ndisc: Optional[int] = 20

Number of discrete colors to use. If None, use a continuous color map.

factor: float = 1.0

A factor to multiply the data with. Useful to convert units

hide_all_ticks: bool = False

Hide all ticks

hide_some_ticks: Union[bool, Sequence[int], None] = True

Hide each second tick

invisible

If True, the colorbar will not be plotted

length = 0.4

Length of the colorbar in nondimensional figure coordinates

norm = None

A norm (matplotlib.norm) to use

offset: float = 0.0

An offset to add to the data, useful to plot e.g. temperature in kelvin

orientation = 'horizontal'

Orientation of the colorbar

symmetrize_min_max = False

Symmetrize the colorbar range. Good for e.g. vorticity fields

thickness = 0.05

Thickness of the colorbar in nondimensional figure coordinates

ticsize = 10

Tick size of the colorbar

class pyoomph.output.plotting.MatplotLibOverlayBase(plotter)[source]

Bases: MatplotLibPart

A base class for any kind of plot object like text, colorbars, etc. that is to be overlaid on a plot.

position: Union[Tuple[float, float], List[float], str, None] = None

Position of the overlay. Can be a tuple/list of floats as coordinates, or a string like "top left", "bottom right", "center", etc.

preprocess_order = 10.0

Order when to preprocess the overlay. The higher the number, the later it will be processed.

textcolor = 'black'

Text color

textsize = 12.0

Text size

xmargin = 0.025

Margin in x direction

xshift = 0.0

Additional shift in x-direction

ymargin = 0.05

Margin in y direction

yshift = 0.0

Additional shift in y-direction

zindex = 10.0

Index of the overlay. The higher the index, the more on top of the plot it will be.

class pyoomph.output.plotting.MatplotlibPlotter(problem=None, filetrunk='plot_{:05d}', fileext='png', eigenvector=None, eigenmode='abs', add_eigen_to_mesh_positions=True, position_eigen_scale=1, eigenscale=1)[source]

Bases: BasePlotter

A class to invoke plotting of 2d problems using matplotlib.

Parameters:
  • problem (Optional[Problem]) – The problem to plot

  • filetrunk (str) – The trunk of the file name to save the plot to (without extension)

  • fileext (Union[str, List[str]]) – The extension of the file to save the plot to

  • eigenvector (Optional[int]) – If set, we plot eigenvector at the given index instead of the solution

  • eigenmode (Literal['abs', 'real', 'imag', 'merge', 'angle']) – If eigenvector is set, this is the mode to plot ( "abs", "real", "imag" )

  • add_eigen_to_mesh_positions (bool) – If eigenvector is set and we have a moving mesh, we can select whether we add the base mesh positions to the eigenvector of the mesh positions

  • position_eigen_scale (float) – If eigenvector is set and we have a moving mesh, we can scale the eigenvector to be added to the actual mesh positions by this factor

  • eigenscale (float) – If eigenvector is set, we can scale the eigenvector by this factor (this includes also the mesh positions)

add_arrow_key(position=None, title=None, factor=None, format=None, unit=None, linewidths=None)[source]

Creates an arrow key to indicate a scale of arrows added at an interface, e.g. for mass transfer.

Parameters:
  • position (Union[str, Tuple[float, float], None]) – The position of the arrow key.

  • title (Optional[str]) – The title of the arrow key.

  • factor (Optional[float]) – Factor to scale the data with. Useful to express the data e.g. in g/(m^2s) instead of kg/(m^2s).

  • format (Optional[str]) – An optional format string.

  • unit (Union[Expression, int, float, None]) – An optional unit of the data.

  • linewidths (Optional[float]) – With of the arrows.

Return type:

MatplotLibArrowKey

Returns:

The arrow key to be used in the add_plot() method.

add_colorbar(title=None, cmap=None, xpos=None, ypos=None, position=None, orientation=None, factor=1.0, unit=None, offset=0.0, length=None, thickness=None, norm=None, vmin=None, vmax=None)[source]

Adds a colorbar to the plot with a given title, colormap, position either by coordinates or by positional string and a lot of other options.

Parameters:
  • title (Optional[str], optional) – Title label of the colorbar. Defaults to None.

  • cmap (Optional[str], optional) – colormap (see matplotlib cmap). Defaults to None.

  • xpos (Optional[float], optional) – x-position. Defaults to None.

  • ypos (Optional[float], optional) – y-position. Defaults to None.

  • position (Optional[Union[str,Tuple[float,float]]], optional) – Use eg. “top center” or “bottom right” to find the correct xpos and ypos. Defaults to None.

  • orientation (Optional[str], optional) – Horizontal or vertical orientation. Defaults to None.

  • factor (Optional[float], optional) – Factor to multiply the plotted results with. Defaults to 1.0.

  • unit (Union[ExpressionNumOrNone,str], optional) – An optional unit. Defaults to None.

  • offset (Optional[float], optional) – An offset to be added to the data, can be e.g. -273.15 to plot a temperature in celsius. Defaults to 0.0.

  • length (Optional[float], optional) – Length of the colorbar. Defaults to None.

  • thickness (Optional[float], optional) – Thickness of the colorbar. Defaults to None.

  • norm (Optional[Any], optional) – How to normalize the data, can be e.g. matplotlib.norm.LogNorm(…). Defaults to None.

  • vmin (Optional[float], optional) – minimum data range. Defaults to None.

  • vmax (Optional[float], optional) – maximum data range. Defaults to None.

Returns:

The colorbar object to be used in e.g. add_plot(”…”,colorbar=…)

Return type:

MatplotLibColorbar

add_plot(infield, mode=None, transform=None, *, linecolor=None, linewidths=None, colorbar=None, arrowkey=None, arrowdensity=None, arrowstyle=None, arrowlength=None, levels=None, datamap=None, axes=None, problem_name='')[source]

Adds a plot of the field infield (e.g. “domain/velocity”) to the current figure. If you pass a colorbar, you will get a color plot of the field (potentially along the interface). If you pass an interface without any mode, you will get an interface line. If you pass and arrowkey for a field at an interface, you will get arrows along the interface, e.g. for indicating mass transfer. Otherwise, you have to set the mode, which can be e.g. “arrows” or “streamlines”.

Parameters: - infield (str): The name of the field to plot, given by the domain and the final field name, e.g. “domain/velocity”. - mode (str, optional): The plotting mode. Defaults to None and then selects on the basis of the other arguments if possible. Otherwise, “streamlines” or “arrows” can be used. - transform (Union[List[Union[PlotTransform, None]], List[Union[str, None]], Union[str, PlotTransform, None]], optional): The transformation to apply to the plot. Defaults to None, but can be e.g. a list of transforms, e.g. also [“mirror_x”,None] to return two plots, one mirrored at the y-axis and one without mirroring. - linecolor (str, optional): The color of the lines in the plot. Defaults to None. - linewidths (float, optional): The width of the lines in the plot. Defaults to None. - colorbar (MatplotLibColorbar, optional): The colorbar to consider for colormap plots. Defaults to None. - arrowkey (MatplotLibArrowKey, optional): The arrow key to use for interface arrow plots. Defaults to None. - arrowdensity (float, optional): The density of the arrows in the plot. Defaults to None. - arrowstyle (str, optional): The style of the arrows (see matplotlib ArrowStyle). Defaults to None. - arrowlength (float, optional): The length of the arrows in the plot. Defaults to None. - levels (int, optional): The number of levels in the plot, e.g. for contour plots . Defaults to None. - datamap (Any, optional): The data map to apply to the plot. Defaults to None. - axes (MatplotLibAxes, optional): The axes to use for the plot. Defaults to None.

Returns: - Union[MatPlotLibAddPlotReturns, List[MatPlotLibAddPlotReturns]]: The added plot or a list of added plots if you use e.g. multiple transforms.

Return type:

Union[MatplotLibPart, MatplotLibOverlayBase, MatplotlibVectorFieldArrows, List[Union[MatplotLibPart, MatplotLibOverlayBase, MatplotlibVectorFieldArrows]]]

add_scale_bar(position=None)[source]

Adds a scale bar to the plot.

Parameters:

position (Optional[Union[str,Tuple[float,float]]], optional) – Either a string like “top left” or explicit coordinates. Defaults to None.

Returns:

The added scalebar

Return type:

MatplotLibScaleBar

add_text(text, position=None, textsize=None, verticalalign=None, horizontalalign=None, bbox=None, zindex=None, color=None)[source]

Adds text to the plot.

Parameters:
  • text (str) – The text to be added.

  • position (Union[str, Tuple[float, float], None]) – The position of the text, either as coordinates or by e.g. "top left".

  • textsize (Optional[float]) – Font size.

  • verticalalign (Optional[str]) – Vertical alignment of the text.

  • horizontalalign (Optional[str]) – Horizontal alignment of the text.

  • bbox (Optional[Any]) – Frame it with an optional box.

  • zindex (Optional[float]) – Index to order the text in the plot, i.e. which text is in front of which.

  • color (Optional[str]) – Text color.

Return type:

MatplotlibText

Returns:

The added text.

add_time_label(position=None)[source]

Adds a label to show the current time.

Parameters:

position (Optional[Union[str,Tuple[float,float]]], optional) – Position like “top center” or “bottom right”. Defaults to None.

Returns:

The time label object. Properties can be set after creation.

Return type:

MatplotlibTimeLabel

background_color: Optional[str]

Set to change the background color of the plot

crash_on_invalid_triangulation: bool

Stop the execution if an invalid triangulation is detected. Otherwise, the plot will be just skipped

dpi: float

DPI of the plot

file_ext

File extension to save the plot. Can also be a list for multiple simultaneous file formats

file_trunk

A format string to save the plot to. The output step will be inserted into the format string

image_size

Size of the plot in pixels

set_view(xmin=None, ymin=None, xmax=None, ymax=None, center=None, size=None)[source]

Set the view range of the plot. Either by setting the min and max values of x and y or by setting the center and size of the view range.

Parameters:
  • xmin (ExpressionNumOrNone, optional) – The minimum x-coordinate of the view. Defaults to None.

  • ymin (ExpressionNumOrNone, optional) – The minimum y-coordinate of the view. Defaults to None.

  • xmax (ExpressionNumOrNone, optional) – The maximum x-coordinate of the view. Defaults to None.

  • ymax (ExpressionNumOrNone, optional) – The maximum y-coordinate of the view. Defaults to None.

  • center (Optional[List[ExpressionOrNum]], optional) – The center coordinates of the view. Defaults to None.

  • size (Optional[List[ExpressionOrNum]], optional) – The size of the view. Defaults to None.

class pyoomph.output.plotting.MatplotlibText(plotter)[source]

Bases: MatplotLibOverlayBase

A text overlay to be used in plots. Create it with MatplotlibPlotter.add_text().

class pyoomph.output.plotting.PlotTransform[source]

Bases: object

Base class to transform the data to be plotted, e.g. by mirroring, rotating, shifting, etc.