ogstools.plot package#
Plotting utilities for simple access.
- ogstools.plot.animate(fig, plot_func, *args, **kwargs)[source]#
Create an animation by applying a plot function on a sequence of meshes.
- Parameters:
fig (Figure) – The figure on which the animation is rendered
plot_func (Callable) – The function which is applied for all timevalues. Expects to read a time value and a mesh.
- Return type:
FuncAnimation
- Positional Arguments:
Sequences where each element corresponds to a frame. plot_func has to accept the individual elements of these sequences as arguments. Most common choice here would be a MeshSeries as an iterator for the meshes and possibly its timevalues for labeling.
- Keyword Arguments:
interval: Delay between frames in milliseconds (default=50).
repeat: Whether the animation repeats at the end.
- ogstools.plot.compute_levels(lower, upper, n_ticks)[source]#
Return an array in the interval [lower, upper] with terminating decimals.
The length of the arrays will be close to n_ticks. At the boundaries the tickspacing may differ from the remaining array.
- Return type:
ndarray
- ogstools.plot.contourf(meshes, variable, fig=None, ax=None, interactive=None, **kwargs)[source]#
Plot the variable field of meshes with default settings.
The resulting figure adheres to the configurations in plot.setup. For 2D meshes matplotlib backend is used, for 3D pyvista backend.
- Parameters:
meshes (list[UnstructuredGrid] | ndarray | UnstructuredGrid) – Singular mesh of 2D numpy array of meshes
variable (Variable | str) – The field to be visualized on all meshes
fig (Figure | None) – matplotlib figure to use for plotting
ax (Axes | None) – matplotlib axis to use for plotting
interactive (bool | None) – By default: 2D mesh -> matplotlib, 3D mesh -> pyvista, if True: always use interactive pyvista plot if False and 3D mesh: -> pyvista static Image
- Return type:
Figure | Plotter | Image | list[Plotter] | list[Image] | None
- Keyword Arguments:
arrowsize scaling factor for arrowsize
cbar: If True (default), draw a colorbar
cb_labelsize: colorbar labelsize
cb_loc: colorbar location (‘left’ or ‘right’)
cb_pad: colorbar padding
cmap: colormap
dpi: resolution
figsize: figure size
fontsize size for labels and captions
levels: user defined levels
log_scaled: logarithmic scaling
min_ax_aspect: minimum axes aspect ratio
max_ax_aspect: maximum axes aspect ratio
show_edges: show element edges
show_max: mark the location of the maximum value
show_min: mark the location of the minimum value
show_region_bounds: show the edges of the different regions
vmin: minimum value
vmax: maximum value
- ogstools.plot.contourf_pv(mesh, variable, show_edges=True, opacities=None, lighting=False, categoric=None, **kwargs)[source]#
General 3D plot using pyvista
- Parameters:
mesh (UnstructuredGrid) – The mesh to be plotted with pyvista.
variable (str | Variable) – The variable which should be shown.
show_edges (bool) – If True, draw edges as black lines
opacities (dict[int, float] | None) – Dictionary, mapping opacities to material ids. Default None (all opaque), Example: {1:0.0 # transparent, 2:1 # opaque, 3:0.5} All not provided ids are rendered as opaque.
lighting (bool) – If True, use lighting in the visualization.
categoric (bool | None) – If True, use a categoric colormap. By default it uses the variable to determine if this should be True.
- Returns:
A pyvista Plotter object. Use .show() to display the scene.
- Return type:
Plotter
- ogstools.plot.heatmap(data, variable, fig=None, ax=None, x_vals=None, y_vals=None, **kwargs)[source]#
Create a heatmap plot of given data.
- Parameters:
data (ndarray) – The two-dimensional data of interest.
variable (Variable) – Provides the label and colormap for the colorbar.
fig (Figure | None) – Optionally plot into this figure.
ax (Axes | None) – Optionally plot into this Axes.
x_vals (ndarray | None) – one-dimensional x_values of the data.
y_vals (ndarray | None) – one-dimensional y_values of the data.
- Return type:
Figure | None
- Keyword Arguments:
figsize: figure size
dpi: resolution
vmin: minimum value of the colorbar
vmax: maximum value of the colorbar
num_levels: Number of levels (approximation)
log_scaled: If True, use logarithmic scaling
aspect: Aspect ratio of the plt.Axes (y/x)
fontsize: fontsize
- Returns:
A figure with a heatmap
- Return type:
Figure | None
- ogstools.plot.line(dataset, var1=None, var2=None, ax=None, sort=True, outer_legend=False, **kwargs)[source]#
Plot some data of a (1D) dataset.
You can pass “x”, “y” or “z” to either of x_var or y_var to specify which spatial dimension should be used for the corresponding axis. By passing “time” the timevalues will be use for this axis. You can also pass two data variables for a phase plot. if no value is given, automatic detection of spatial axis is tried.
>>> line(ms, ot.variables.temperature) # temperature over time >>> line(ms, ot.variables.temperature, "time") # time over temperature >>> line(ms, "pressure", "temperature") # temperature over pressure >>> line(mesh, ot.variables.temperature) # temperature over x, y or z >>> line(mesh, "y", "temperature") # temperature over y >>> line(mesh, ot.variables.pressure, "y") # y over pressure >>> line(mesh) # z=const: y over x, y=const: z over x, x=const: z over y
- Parameters:
dataset (DataSet | Sequence[DataSet]) – The mesh or meshseries which contains the data to plot.
var1 (str | Variable | None) – Variable for the x-axis if var2 is given else for y-axis.
var2 (str | Variable | None) – Variable for the y-axis if var1 is given.
ax (Axes | None) – The matplotlib axis to use for plotting, if None a new figure will be created.
sort (bool) – Automatically sort the values along the dimension of the mesh with the largest extent (only for pointclouds).
- Outer_legend:
Draw legend to the right next to the plot area. By default False (legend stays inside). User can pass a tuple of two floats (x, y), which will be passed to bbox_to_anchor parameter in matplotlib legend call. True will pass the default values (1.05, 1.0).
- Return type:
Figure | None
- Keyword Arguments:
figsize: figure size (default=[16, 10])
dpi: resolution of the figure
color: color of the line
linewidth: width of the line
linestyle: style of the line
label: label in the legend
grid: if True, show grid
monospace: if True, the legend uses a monospace font
loc: location of the legend (default=”upper right”)
- clip_on: If True, clip the output to stay within the Axes.
(default=False)
all other kwargs get passed to matplotlib’s plot function
- Note:
Using loc=”best” will take a long time, if you plot lines on top of a contourplot, as matplotlib is calculating the best position against all the underlying cells.
- ogstools.plot.quiver(mesh, ax, variable, arrowsize=None, projection=None, glyph_type='arrow')[source]#
Plot arrows or lines corresponding to vectors on a matplotlib axis.
- Parameters:
mesh (DataSet) – Mesh containing the vector variable
ax (Axes) – Matplotlib axis to plot onto
variable (Vector) – Vector variable to visualize
arrowsize (float | None) – Sets size of arrows in the plot.
projection (int | None) – Index of flat dimension (e.g. 2 for z axis), gets automatically determined if not given
glyph_type (Literal['arrow', 'line']) – Whether to plot arrows or lines.
- ogstools.plot.streamlines(mesh, ax, variable, arrowsize=None, projection=None)[source]#
Plot the vector streamlines on a matplotlib axis.
- Parameters:
mesh (DataSet) – Mesh containing the vector variable
ax (Axes) – Matplotlib axis to plot onto
variable (Vector) – Vector variable to visualize
arrowsize (float | None) – Sets size of arrows in the plot.
projection (int | None) – Index of flat dimension (e.g. 2 for z axis), gets automatically determined if not given
- ogstools.plot.subplot(mesh, variable, ax, levels=None, **kwargs)[source]#
Plot the variable field of a mesh on a matplotlib.axis.
- Parameters:
mesh (UnstructuredGrid) – singular mesh
variable (Variable | str) – the field to be visualized on all meshes
ax (Axes) – matplotlib ax to use for plotting
levels (ndarray | None) – value levels
Matplotlib kwargs are also accepted.
Submodules#
- ogstools.plot.animation module
- ogstools.plot.contourplots module
- ogstools.plot.contourplots_pv module
- ogstools.plot.features module
- ogstools.plot.heatmaps module
- ogstools.plot.levels module
- ogstools.plot.lineplots module
- ogstools.plot.plot_setup module
PlotSetupPlotSetup.combined_colorbarPlotSetup.custom_cmapPlotSetup.continuous_cmapPlotSetup.dpiPlotSetup.min_ax_aspectPlotSetup.max_ax_aspectPlotSetup.invert_colorbarPlotSetup.layoutPlotSetup.material_namesPlotSetup.num_levelsPlotSetup.num_streamline_interp_ptsPlotSetup.vmaxPlotSetup.__init__()PlotSetup.vminPlotSetup.show_element_edgesPlotSetup.log_scaledPlotSetup.show_region_boundsPlotSetup.tick_padPlotSetup.tick_lengthPlotSetup.fontsizePlotSetup.linewidthPlotSetup.label_splitPlotSetup.arrowsizePlotSetup.from_dict()PlotSetup.reset()
- ogstools.plot.plot_setup_defaults module
- ogstools.plot.shared module
- ogstools.plot.utils module
- ogstools.plot.vectorplots module