general_plotter#

ansys.mapdl.core.plotting.general_plotter(meshes, points, labels, *, title='', cpos=None, show_bounds=False, show_axes=True, background=None, off_screen=None, savefig=None, window_size=None, notebook=None, style=None, color='w', show_edges=None, edge_color=None, point_size=5.0, line_width=None, opacity=1.0, flip_scalars=False, lighting=None, n_colors=256, interpolate_before_map=True, cmap=None, render_points_as_spheres=False, render_lines_as_tubes=False, scalar_bar_args={}, smooth_shading=None, show_scalar_bar=None, split_sharp_edges=None, font_size=None, font_family=None, text_color=None, theme=None, return_plotter=False, return_cpos=False, mapdl=None, plot_bc=False, plot_bc_legend=None, plot_bc_labels=None, bc_labels=None, bc_target=None, bc_glyph_size=None, bc_labels_font_size=16, plotter=None, add_points_kwargs={}, add_mesh_kwargs={}, add_point_labels_kwargs={}, plotter_kwargs={})[source]#

General pymapdl plotter for APDL geometry and meshes.

Parameters:
titlestr, optional

Add given title to plot.

cposlist(tuple(floats)), str

The camera position to use. You can either use a saved camera position or specify one of the following strings:

  • "xy"

  • "xz"

  • "yz"

  • "yx"

  • "zx"

  • "zy"

  • "iso"

off_screenbool, optional

Renders off screen when True. Useful for automated screenshots.

window_sizelist, optional

Window size in pixels. Defaults to [1024, 768]

notebookbool, optional

When True, the resulting plot is placed inline a jupyter notebook. Assumes a jupyter console is active. Automatically enables off_screen.

show_boundsbool, optional

Shows mesh bounds when True.

show_axesbool, optional

Shows a vtk axes widget. Enabled by default.

savefigstr, optional

Saves screenshot to a file path.

stylestr, optional

Visualization style of the mesh. One of the following: style='surface', style='wireframe', style='points'. Defaults to 'surface'. Note that 'wireframe' only shows a wireframe of the outer geometry.

colorstr, list[int, int, int], optional

Use to make the entire mesh have a single solid color. Either a string, RGB list, or hex color string. For example: color='white', color='w', color=[1, 1, 1], or color='#FFFFFF'. Color will be overridden if scalars are specified.

show_edgesbool, optional

Shows the edges of a mesh. Does not apply to a wireframe representation.

edge_colorstr, list[int, int, int], optional

The solid color to give the edges when show_edges=True. Either a string, RGB list, or hex color string. Defaults to black.

point_sizefloat, optional

Point size of any nodes in the dataset plotted. Also applicable when style=’points’. Default 5.0

line_widthfloat, optional

Thickness of lines. Only valid for wireframe and surface representations. Default None.

opacityfloat, str, array_like

Opacity of the mesh. If a single float value is given, it will be the global opacity of the mesh and uniformly applied everywhere - should be between 0 and 1. A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’). A string could also be used to map a scalars array from the mesh to the opacity (must have same number of elements as the scalars argument). Or you can pass a custom made transfer function that is an array either n_colors in length or shorter.

n_colorsint, optional

Number of colors to use when displaying scalars. Defaults to 256. The scalar bar will also have this many colors.

cmapstr, list, optional

Name of the Matplotlib colormap to us when mapping the scalars. See available Matplotlib colormaps. Only applicable for when displaying scalars. Requires Matplotlib to be installed. colormap is also an accepted alias for this. If colorcet or cmocean are installed, their colormaps can be specified by name.

You can also specify a list of colors to override an existing colormap with a custom one. For example, to create a three color colormap you might specify ['green', 'red', 'blue']

render_points_as_spheresbool, optional

Render points as spheres.

render_lines_as_tubesbool, optional

Renders lines as tubes.

smooth_shadingbool, optional

Smoothly render curved surfaces when plotting. Not helpful for all meshes.

themepyvista.DefaultTheme, optional

PyVista theme. Defaults to PyMAPDL theme.

return_plotterbool, optional

Return the plotting object rather than showing the plot and returning the camera position. Default False. This overrides the return_cpos value.

return_cposbool, optional

Returns the camera position as an array. Default False.

mapdlMapdl instance, optional

If you want to use plot_bc keyword, the MAPDL instance needs to be passed as argument. Defaults to None

plot_bcbool, optional

Activate the plotting of the boundary conditions. Defaults to False.

Warning

This is in alpha state.

plot_bc_legendbool, optional

Shows the boundary conditions legend. Defaults to False

plot_bc_labelsbool, optional

Shows the boundary conditions label per node. Defaults to False.

bc_labelsList[str], Tuple(str), optional

List or tuple of strings with the boundary conditions to plot, i.e. [“UX”, “UZ”]. You can obtain the allowed boundary conditions by evaluating ansys.mapdl.core.plotting.BCS. You can use also the following shortcuts:

  • ‘mechanical’ To plot the following mechanical boundary conditions: ‘UX’, ‘UY’, ‘UZ’, ‘FX’, ‘FY’, and ‘FZ’. Rotational or momentum boundary conditions are not allowed.

  • ‘thermal’ To plot the following boundary conditions: ‘TEMP’ and ‘HEAT’.

  • ‘electrical’ To plot the following electrical boundary conditions: ‘VOLT’, ‘CHRG’, and ‘AMPS’.

Defaults to all the allowed boundary conditions present in the responses of ansys.mapdl.core.Mapdl.dlist() and ansys.mapdl.core.Mapdl.flist().

bc_targetList[str], Tuple(str), optional

Specify the boundary conditions target to plot, i.e. “Nodes”, “Elements”. You can obtain the allowed boundary conditions target by evaluating ansys.mapdl.core.plotting.ALLOWED_TARGETS. Defaults to only Nodes.

bc_glyph_sizefloat, optional

Specify the size of the glyph used for the boundary conditions plotting. By default is ratio of the bounding box dimensions.

bc_labels_font_sizefloat, optional

Size of the text on the boundary conditions labels. By default it is 16.

plotterpyvista.Plotter, optional

If a pyvista.Plotter is not provided, then creates its own plotter. If a pyvista.Plotter is provided, the plotter is not shown (you need to issue pyvista.Plotter.show() manually) and the arguments notebook, off_screen and theme are ignored, since they should be set when instantiated the provided plotter. Defaults to None (create the Plotter object).

add_points_kwargsList[dict]

This is a dict or list of dicts to be passed to all or just the correspondent pyvista.Plotter.add_points call in ansys.mapdl.core.plotting.general_plotter(). This pyvista method is used to plot nodes for example. See examples section to learn more about its usage.

add_mesh_kwargsList[dict]

This is a dict or list of dicts to be passed to all or just the correspondent pyvista.Plotter.add_mesh call in ansys.mapdl.core.plotting.general_plotter(). This pyvista method is used to plot elements for example. See examples section to learn more about its usage.

add_point_labels_kwargsList[dict]

This is a dict or list of dicts to be passed to all or just the correspondent pyvista.Plotter.add_point_labels call in ansys.mapdl.core.plotting.general_plotter(). This pyvista method is used to plot node labels for example. See examples section to learn more about its usage.

plotter_kwargsdict

This is a dict which is passed to the pyvista.Plotter initializer in ansys.mapdl.core.plotting.general_plotter(). This pyvista class is used in all PyMAPDL plots. See examples section to learn more about its usage.

Returns:
cpos or pyvista.Plotter or None

Camera position or instance of pyvista.Plotter or None depending on return_plotter and return_cpos.

Notes

Plotting boundary conditions is still under-development, so feel free to share feedback or suggestion in PyMAPDL. At the moment only nodal boundary conditions can be shown (bc_target='Nodes'), and only the following types of boundary conditions:

Field

Boundary conditions

MECHANICAL

[“UX”, “UY”, “UZ”, “FX”, “FY”, “FZ”]

THERMAL

[“TEMP”, “HEAT”]

ELECTRICAL

[“VOLT”, “CHRG”, “AMPS”]

Examples

Plot areas and modify the background color to 'black'

>>> cpos = mapdl.aplot(background='black')

Enable smooth_shading on an element plot.

>>> cpos = mapdl.eplot(smooth_shading=True)

Plot boundary conditions “UX” and “UZ” on the nodes:

>>> mapdl.nplot(plot_bc=True, bc_labels=["UX", "UZ"], plot_bc_labels=True)

Return the plotting instance, modify it, and display the plot.

>>> pl = mapdl.aplot(return_plotter=True)
>>> pl.show_bounds()
>>> pl.set_background('black')
>>> pl.add_text('my text')
>>> pl.show()

Save a screenshot to disk without showing the plot.

>>> mapdl.eplot(background='w', show_edges=True, smooth_shading=True,
                window_size=[1920, 1080], savefig='screenshot.png',
                off_screen=True)

Using add_mesh_kwargs to pass other arguments to add_mesh pyvista method.

>>> mapdl.eplot(background='w', show_edges=True, add_mesh_kwargs = {"use_transparency": False})

Using plotter_kwargs to pass other arguments to Plotter constructor.

>>> mapdl.eplot(background='w', show_edges=True, plotter_kwargs = {"polygon_smoothing": False})