PlotlyBackend#

class ansys.tools.visualization_interface.backends.plotly.plotly_interface.PlotlyBackend#

Bases: ansys.tools.visualization_interface.backends._base.BaseBackend

Plotly interface for visualization.

Overview#

plot_iter

Plot multiple objects using Plotly.

plot

Plot a single object using Plotly.

show

Render the Plotly scene.

add_points

Add point markers to the scene.

add_lines

Add line segments to the scene.

add_planes

Add a plane to the scene.

add_text

Add text to the scene.

add_labels

Add labels at 3D point locations.

clear

Clear all traces from the figure.

layout

Get the current layout of the Plotly figure.

Import detail#

from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend

Property detail#

property PlotlyBackend.layout: Any#

Get the current layout of the Plotly figure.

Returns:
Any

The current layout of the Plotly figure.

Method detail#

PlotlyBackend.plot_iter(plotting_list: Iterable[Any]) None#

Plot multiple objects using Plotly.

Parameters:
plotting_listIterable[Any]

An iterable of objects to plot.

PlotlyBackend.plot(plottable_object: pyvista.PolyData | pyvista.MultiBlock | ansys.tools.visualization_interface.types.mesh_object_plot.MeshObjectPlot | plotly.graph_objects.Mesh3d, name: str = None, **plotting_options) None#

Plot a single object using Plotly.

Parameters:
plottable_objectUnion[PolyData, pv.MultiBlock, MeshObjectPlot, go.Mesh3d]

The object to plot. Can be a PyVista PolyData, MultiBlock, a MeshObjectPlot, or a Plotly Mesh3d.

plotting_optionsdict

Additional plotting options.

namestr, optional

Name of the mesh for labeling in Plotly. Overrides the name from MeshObjectPlot if provided.

PlotlyBackend.show(plottable_object=None, screenshot: str = None, name_filter=None, **kwargs) plotly.graph_objects.Figure | None#

Render the Plotly scene.

Parameters:
plottable_objectAny, optional

Object to show, by default None.

screenshotstr, optional

Path to save a screenshot, by default None.

name_filterbool, optional

Flag to filter the object, by default None.

kwargsdict

Additional options the selected backend accepts.

Returns:
Union[go.Figure, None]

The figure of the plot if in doc building environment. Else, None.

PlotlyBackend.add_points(points: List | Any, color: str = 'red', size: float = 10.0, **kwargs) Any#

Add point markers to the scene.

Parameters:
pointsUnion[List, Any]

Points to add. Expected format: [[x1, y1, z1], [x2, y2, z2], …] or Nx3 array.

colorstr, default: “red”

Color of the points.

sizefloat, default: 10.0

Size of the point markers.

**kwargsdict

Additional keyword arguments passed to Plotly’s Scatter3d.

Returns:
go.Scatter3d

Plotly Scatter3d trace representing the added points.

PlotlyBackend.add_lines(points: List | Any, connections: List | Any | None = None, color: str = 'white', width: float = 1.0, **kwargs) Any#

Add line segments to the scene.

Parameters:
pointsUnion[List, Any]

Points defining the lines. Expected format: [[x1, y1, z1], [x2, y2, z2], …] or Nx3 array.

connectionsOptional[Union[List, Any]], default: None

Line connectivity. If None, connects points sequentially. Expected format: [[start_idx1, end_idx1], [start_idx2, end_idx2], …] or Mx2 array.

colorstr, default: “white”

Color of the lines.

widthfloat, default: 1.0

Width of the lines.

**kwargsdict

Additional keyword arguments passed to Plotly’s Scatter3d.

Returns:
Union[go.Scatter3d, List[go.Scatter3d]]

Plotly Scatter3d trace(s) representing the added lines.

PlotlyBackend.add_planes(center: Tuple[float, float, float] = (0.0, 0.0, 0.0), normal: Tuple[float, float, float] = (0.0, 0.0, 1.0), i_size: float = 1.0, j_size: float = 1.0, **kwargs) Any#

Add a plane to the scene.

Parameters:
centerTuple[float, float, float], default: (0.0, 0.0, 0.0)

Center point of the plane (x, y, z).

normalTuple[float, float, float], default: (0.0, 0.0, 1.0)

Normal vector of the plane (x, y, z).

i_sizefloat, default: 1.0

Size of the plane in the i direction.

j_sizefloat, default: 1.0

Size of the plane in the j direction.

**kwargsdict

Additional keyword arguments passed to Plotly’s Mesh3d (e.g., color, opacity).

Returns:
go.Mesh3d

Plotly Mesh3d trace representing the added plane.

PlotlyBackend.add_text(text: str, position: Tuple[float, float] | Tuple[float, float, float] | str, font_size: int = 12, color: str = 'white', **kwargs) Any#

Add text to the scene.

Parameters:
textstr

Text string to display.

positionUnion[Tuple[float, float], Tuple[float, float, float], str]

Position for the text as 2D screen coordinates (x, y). Values should be between 0 and 1 for normalized coordinates, or pixel values for absolute positioning.

font_sizeint, default: 12

Font size for the text.

colorstr, default: “white”

Color of the text.

**kwargsdict

Additional keyword arguments passed to Plotly’s annotation.

Returns:
dict

Plotly annotation representing the added text.

PlotlyBackend.add_labels(points: List | Any, labels: List[str], font_size: int = 12, point_size: float = 5.0, **kwargs) Any#

Add labels at 3D point locations.

Parameters:
pointsUnion[List, Any]

Points where labels should be placed.

labelsList[str]

List of label strings to display at each point.

font_sizeint, default: 12

Font size for the labels.

point_sizefloat, default: 5.0

Size of the point markers shown with labels.

**kwargsdict

Additional keyword arguments.

Returns:
Any

Plotly trace representing the labels.

PlotlyBackend.clear() None#

Clear all traces from the figure.