plotting moduleο
- class wakis.plotting.PlotMixin[source]ο
Bases:
objectPlotting mixin providing 1D/2D/3D visualization helpers.
- inspect(wake=None, window_size=None, off_screen=False, opacity=1.0, inactive_opacity=0.1, add_silhouette=False, specular=0.5, smooth_shading=False)[source]ο
Interactive inspection of STL solids and optional wake geometry.
Provides a PyVista-based UI to toggle visibility and highlighting for the package STL solids. When a
wakeobject is provided the method also creates a beam and an integration-path actor and exposes check boxes to toggle them. A master checkbox toggles all solids at once.- Parameters
wake (object or None, optional) β Optional wake-like object (for example a
WakeSolverinstance) that providesxsource,ysource,xtestandytestattributes used to place a beam and an integration path. When provided the object is stored asself.wake. DefaultNone.window_size (sequence or None, optional) β Tuple
(width, height)passed topyvista.Plotterto set the window size. DefaultNone(use PyVista defaults).off_screen (bool, optional) β If True the plotter is not shown interactively and the method returns the created
pyvista.Plotterinstance for programmatic control and screenshot capture. DefaultFalse.opacity (float, optional) β Opacity applied to solids when they are active/highlighted (default 1.0).
inactive_opacity (float, optional) β Opacity applied to solids when inactive (default 0.1).
add_silhouette (bool, optional) β When True add a silhouette actor behind each solid for emphasis.
specular (float, optional) β Specular lighting value forwarded to
pyvista.Plotter.add_meshfor STL actors (default 0.5).smooth_shading (bool, optional) β Enable smooth shading for STL meshes (default False).
- Returns
Returns the created
pyvista.Plotterwhenoff_screenis True so the caller can save screenshots or control rendering programmatically. Otherwise shows the interactive window and returnsNone.- Return type
pyvista.Plotter or None
Notes
The method expects
self.stl_solidsandself.stl_colorsto be populated and usesself.grid.read_stl(key)to load surfaces.When running under MPI the method prints a warning and returns immediately (interactive plotting is not supported under MPI).
- plot1D(field='E', component='z', line='z', pos=[0.5], xscale='linear', yscale='linear', xlim=None, ylim=None, figsize=[8, 4], title=None, off_screen=False, n=None, colors=None, **kwargs)[source]ο
Built-in 1D plotting of a field line using matplotlib.
Plots 1D cuts along a grid line (x, y or z) for the selected field component. Supports plotting multiple positions and MPI gathering when running in parallel.
- Parameters
field (str, optional) β Field to plot: βEβ, βHβ, or βJβ. Two-letter values (e.g. βExβ) are accepted and override
component. Default βEβ.component (str, optional) β Component to plot (βxβ,βyβ,βzβ,βAbsβ). Default βzβ.
line (str or sequence, optional) β Line specification as βxβ,βyβ,βzβ or a sequence of three indices or slices (e.g. [0, slice(10,Ny-10), 0]). Default βzβ.
pos (float or sequence, optional) β Relative position(s) (0-1) used when
lineis a single-axis specifier. Default 0.5.xscale (str, optional) β Axis scaling passed to matplotlib (default βlinearβ).
yscale (str, optional) β Axis scaling passed to matplotlib (default βlinearβ).
xlim (sequence, optional) β Axis limits for the plot.
ylim (sequence, optional) β Axis limits for the plot.
figsize (sequence, optional) β Figure size for the matplotlib figure (default [8,4]).
title (str, optional) β Basename used to save screenshots when
off_screen=True.off_screen (bool, optional) β If True save the figure to disk instead of showing it interactively.
n (int, optional) β Timestep index appended to saved filenames.
colors (sequence, optional) β Colors used for each plotted line when multiple positions are requested.
**kwargs (dict) β Extra keyword arguments forwarded to
matplotlib.axes.Axes.plot.
- Return type
None
Notes
When running with MPI (use_mpi=True), only rank 0 will display or save the figure.
- plot2D(field='E', component='z', plane='ZY', pos=0.5, norm=None, vmin=None, vmax=None, figsize=[8, 4], cmap='jet', patch_alpha=0.1, patch_reverse=False, add_patch=False, title=None, off_screen=False, n=None, interpolation='antialiased', dpi=100, return_handles=False)[source]ο
Built-in 2D plotting of a field slice using matplotlib.
Renders a 2D cut through the structured grid and displays the selected field component using
matplotlib.pyplot.imshow. Optionally adds a patch showing STL masks as overlays.- Parameters
field (str, optional) β Field to plot: βEβ, βHβ, or βJβ. Two-letter values (e.g. βExβ) are accepted and override
component. Default βEβ.component (str, optional) β Component to plot (βxβ,βyβ,βzβ,βAbsβ). Default βzβ.
plane (str or sequence, optional) β Cut plane specified as βXYβ, βZYβ, βZXβ or a sequence of slices and an integer index
[x,y,z]. Default βXZβ.pos (float, optional) β Relative position in the normal direction for the cut (0-1). Default 0.5 (center).
norm (str or None, optional) β Color normalization for
imshow(βlinearβ,βlogβ,βsymlogβ).vmin (scalar, optional) β Color limits for the plot.
vmax (scalar, optional) β Color limits for the plot.
figsize (sequence, optional) β Figure size for the matplotlib figure (default [8,4]).
cmap (str, optional) β Colormap for the field plot (default βjetβ).
patch_alpha (float, optional) β Alpha value for STL mask overlays (default 0.1).
patch_reverse (bool, optional) β If True, reverse the mask for the patch overlay.
add_patch (str or list, optional) β STL key or list of keys to overlay as a mask patch on the plot.
title (str, optional) β Basename used to save screenshots when
off_screen=True.off_screen (bool, optional) β If True save the figure to disk instead of showing it interactively.
n (int, optional) β Timestep index appended to saved filenames.
interpolation (str, optional) β Interpolation method for
imshow(default βantialiasedβ).dpi (int, optional) β Dots per inch for the figure (default 100).
return_handles (bool, optional) β If True return the
(fig, ax)handles instead of showing.
- Returns
Returns (fig, ax) if
return_handles=True, otherwise None.- Return type
None or tuple
Notes
When running with MPI (use_mpi=True), only rank 0 will display or save the figure.
STL patch overlays are not supported when running under MPI.
- plot3D(field='E', component='z', clim=None, hide_solids=None, show_solids=None, add_stl=None, stl_opacity=0.1, stl_colors='white', title=None, cmap='jet', clip_interactive=True, clip_normal='-y', clip_box=False, clip_bounds=None, off_screen=False, zoom=0.5, camera_position=None, nan_opacity=1.0, n=None)[source]ο
Built-in 3D plotting using PyVista.
Displays a cell-centered field (E, H or J) on the structured grid using PyVista. Optionally overlays STL solids, clipping widgets or a static clip box. When rendered off-screen the plot can be saved to a PNG file for later composition into animations.
- Parameters
field (str, optional) β 3D field magnitude to plot: βEβ, βHβ, or βJβ. A two-letter value (e.g., βExβ) is accepted to plot a single component; in that case
componentis overridden. Default βEβ.component (str, optional) β Component of the field to plot: βxβ, βyβ, βzβ, or βAbsβ. Default βzβ. Overridden when
fieldcontains a component.clim (sequence, optional) β Colorbar limits for the field plot as
[min, max].hide_solids (str, list, or None, optional) β If provided, mask values inside the named STL solids to
np.nan. NaNs are shown in grey due to a known PyVista opacity limitation.show_solids (str, list, or None, optional) β If provided, mask values outside the named STL solids to
np.nan.add_stl (str or list, optional) β STL solid key or list of keys to add to the scene via
pv.add_mesh.stl_opacity (float, optional) β Opacity for STL surfaces (0 transparent, 1 opaque). Default 0.1.
stl_colors (str or list, optional) β Color or list of colors for STL surfaces (default βwhiteβ).
title (str, optional) β Basename used to save screenshots when
off_screen=True.cmap (str, optional) β Colormap name for the field display (default βjetβ).
clip_interactive (bool, optional) β Enable an interactive clipping plane widget (default False).
clip_normal (str, optional) β Normal direction for the interactive clip plane (default β-yβ).
clip_box (bool, optional) β Enable a static box clipping of the domain (default False).
clip_bounds (sequence, optional) β Box bounds as
[xmin,xmax,ymin,ymax,zmin,zmax]whenclip_boxis active.off_screen (bool, optional) β Render off-screen and save screenshots instead of opening an interactive window (default False).
zoom (float, optional) β Camera zoom factor (default 0.5).
camera_position (str, sequence, or None, optional) β Camera position preset or coordinates (default None).
nan_opacity (float, optional) β Opacity for NaN values produced by masking (default 1.0).
n (int, optional) β Timestep index appended to saved screenshot filenames.
- Return type
None
Notes
When running with MPI (use_mpi=True), plotting is not supported.
The method modifies the PyVista plotter state and may save screenshots if off_screen=True.
- plot3DonSTL(field='E', component='z', clim=None, cmap='jet', log_scale=False, stl_with_field=None, field_opacity=1.0, tolerance=None, stl_transparent=None, stl_opacity=0.1, stl_colors='white', clip_plane=False, clip_interactive=False, clip_normal='-x', clip_origin=[0, 0, 0], clip_box=False, clip_bounds=None, title=None, off_screen=False, n=None, zoom=0.5, camera_position=None, **kwargs)[source]ο
Built-in 3D plotting sampling fields onto STL surfaces.
Samples a cell-centered field onto STL surfaces and visualizes the sampled field. Supports clipping with a plane or a static box and rendering the STL surfaces with or without sampled field data.
- Parameters
field (str, optional) β Field to sample and plot: βEβ, βHβ, or βJβ. Two-letter values like βExβ are accepted and override
component. Default βEβ.component (str, optional) β Component to plot (βxβ, βyβ, βzβ, βAbsβ). Default βzβ.
clim (sequence, optional) β Color limits for the plotted field.
cmap (str, Colormap, optional) β Colormap for field rendering (default βjetβ).
log_scale (bool, optional) β Use logarithmic color scaling when True (default False).
stl_with_field (str or list, optional) β STL key or list of keys whose surfaces will be sampled with the selected field.
field_opacity (float, optional) β Opacity for the sampled field rendering on STL surfaces.
tolerance (float, optional) β Sampling tolerance passed to
pyvista.PolyData.sample.stl_transparent (str or list, optional) β STL solids to add to the scene with transparent rendering.
stl_opacity (float, optional) β Opacity for non-sampled STL solids (default 0.1).
stl_colors (str or list, optional) β Colors used for STL solids (default βwhiteβ).
clip_interactive (bool, optional) β Enable an interactive clipping plane for sampled surfaces.
clip_plane (bool, optional) β Clip the STL surface with a plane and show the field on the plane.
clip_normal (str, optional) β Normal direction for clipping operations (default β-xβ).
clip_origin (sequence, optional) β Origin for planar clipping when
clip_planeis True.clip_box (bool, optional) β Clip sampled surfaces using a static box (default False).
clip_bounds (sequence, optional) β Bounds for the static clip box as
[xmin,xmax,ymin,ymax,zmin,zmax].title (str, optional) β Basename used to save screenshots when
off_screen=True.off_screen (bool, optional) β Render off-screen and save screenshots when True.
n (int, optional) β Timestep index appended to saved filenames.
zoom (float, optional) β Camera zoom factor (default 0.5).
camera_position (str, sequence, or None, optional) β Camera position preset or coordinates (default None).
**kwargs (dict) β Extra keyword arguments forwarded to
pyvista.Plotter.add_mesh.
- Return type
None
Notes
When running with MPI (use_mpi=True), plotting is not supported.
The method modifies the PyVista plotter state and may save screenshots if off_screen=True.