:class:`PlotlyBackend` ====================== .. py:class:: ansys.tools.visualization_interface.backends.plotly.plotly_interface.PlotlyBackend Bases: :py:obj:`ansys.tools.visualization_interface.backends._base.BaseBackend` Plotly interface for visualization. .. !! processed by numpydoc !! .. py:currentmodule:: PlotlyBackend Overview -------- .. tab-set:: .. tab-item:: Methods .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~plot_iter` - Plot multiple objects using Plotly. * - :py:attr:`~plot` - Plot a single object using Plotly. * - :py:attr:`~set_trace_visibility` - Set the visibility of all traces with the given name. * - :py:attr:`~filter_traces` - Show only traces whose names are in the provided list, hiding all others. * - :py:attr:`~show` - Render the Plotly scene. * - :py:attr:`~add_points` - Add point markers to the scene. * - :py:attr:`~add_lines` - Add line segments to the scene. * - :py:attr:`~add_planes` - Add a plane to the scene. * - :py:attr:`~add_text` - Add text to the scene. * - :py:attr:`~add_labels` - Add labels at 3D point locations. * - :py:attr:`~clear` - Clear all traces from the figure. .. tab-item:: Properties .. list-table:: :header-rows: 0 :widths: auto * - :py:attr:`~layout` - Get the current layout of the Plotly figure. Import detail ------------- .. code-block:: python from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend Property detail --------------- .. py:property:: layout :type: Any Get the current layout of the Plotly figure. :Returns: :obj:`Any` The current layout of the Plotly figure. .. !! processed by numpydoc !! Method detail ------------- .. py:method:: plot_iter(plotting_list: Iterable[Any], **kwargs) -> None Plot multiple objects using Plotly. :Parameters: **plotting_list** : :obj:`Iterable`\[:obj:`Any`] An iterable of objects to plot. **kwargs** : :class:`python:dict` Additional plotting options. .. !! processed by numpydoc !! .. py:method:: plot(plottable_object: Union[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_object** : :obj:`Union`\[:obj:`PolyData`, :obj:`pv.MultiBlock`, :obj:`MeshObjectPlot`, :obj:`go.Mesh3d`] The object to plot. Can be a PyVista PolyData, MultiBlock, a MeshObjectPlot, or a Plotly Mesh3d. **name** : :class:`python:str`, :obj:`optional` Name of the mesh for labeling in Plotly. Overrides the name from MeshObjectPlot if provided. **plotting_options** : :class:`python:dict` Additional plotting options. .. !! processed by numpydoc !! .. py:method:: set_trace_visibility(name: str, visible: bool) -> None Set the visibility of all traces with the given name. :Parameters: **name** : :class:`python:str` Name of the trace(s) to update. **visible** : :ref:`bool ` Whether to make the trace(s) visible. .. !! processed by numpydoc !! .. py:method:: filter_traces(names: List[str]) -> None Show only traces whose names are in the provided list, hiding all others. :Parameters: **names** : :obj:`List`\[:class:`python:str`] Names of traces to show. All other traces will be hidden. .. !! processed by numpydoc !! .. py:method:: show(plottable_object=None, screenshot: str = None, **kwargs) -> Union[plotly.graph_objects.Figure, None] Render the Plotly scene. :Parameters: **plottable_object** : :obj:`Any`, :obj:`optional` Object to show, by default None. **screenshot** : :class:`python:str`, :obj:`optional` Path to save a screenshot, by default None. **kwargs** : :class:`python:dict` Additional options the selected backend accepts. :Returns: :obj:`Union`\[:obj:`go.Figure`, :data:`python:None`] The figure of the plot if in doc building environment. Else, None. .. !! processed by numpydoc !! .. py:method:: add_points(points: Union[List, Any], color: str = 'red', size: float = 10.0, **kwargs) -> Any Add point markers to the scene. :Parameters: **points** : :obj:`Union`\[:obj:`List`, :obj:`Any`] Points to add. Expected format: [[x1, y1, z1], [x2, y2, z2], ...] or Nx3 array. **color** : :class:`python:str`, default: "red" Color of the points. **size** : :class:`python:float`, default: 10.0 Size of the point markers. **\*\*kwargs** : :class:`python:dict` Additional keyword arguments passed to Plotly's Scatter3d. :Returns: :obj:`go.Scatter3d` Plotly Scatter3d trace representing the added points. .. !! processed by numpydoc !! .. py:method:: add_lines(points: Union[List, Any], connections: Optional[Union[List, Any]] = None, color: str = 'white', width: float = 1.0, **kwargs) -> Any Add line segments to the scene. :Parameters: **points** : :obj:`Union`\[:obj:`List`, :obj:`Any`] Points defining the lines. Expected format: [[x1, y1, z1], [x2, y2, z2], ...] or Nx3 array. **connections** : :obj:`Optional`\[:obj:`Union`\[:obj:`List`, :obj:`Any`]], default: :data:`python:None` Line connectivity. If None, connects points sequentially. Expected format: [[start_idx1, end_idx1], [start_idx2, end_idx2], ...] or Mx2 array. **color** : :class:`python:str`, default: "white" Color of the lines. **width** : :class:`python:float`, default: 1.0 Width of the lines. **\*\*kwargs** : :class:`python:dict` Additional keyword arguments passed to Plotly's Scatter3d. :Returns: :obj:`Union`\[:obj:`go.Scatter3d`, :obj:`List`\[:obj:`go.Scatter3d`]] Plotly Scatter3d trace(s) representing the added lines. .. !! processed by numpydoc !! .. py:method:: 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: **center** : :obj:`Tuple`\[:class:`python:float`, :class:`python:float`, :class:`python:float`], default: (0.0, 0.0, 0.0) Center point of the plane (x, y, z). **normal** : :obj:`Tuple`\[:class:`python:float`, :class:`python:float`, :class:`python:float`], default: (0.0, 0.0, 1.0) Normal vector of the plane (x, y, z). **i_size** : :class:`python:float`, default: 1.0 Size of the plane in the i direction. **j_size** : :class:`python:float`, default: 1.0 Size of the plane in the j direction. **\*\*kwargs** : :class:`python:dict` Additional keyword arguments passed to Plotly's Mesh3d (e.g., color, opacity). :Returns: :obj:`go.Mesh3d` Plotly Mesh3d trace representing the added plane. .. !! processed by numpydoc !! .. py:method:: add_text(text: str, position: Union[Tuple[float, float], Tuple[float, float, float], str], font_size: int = 12, color: str = 'white', **kwargs) -> Any Add text to the scene. :Parameters: **text** : :class:`python:str` Text string to display. **position** : :obj:`Union`\[:obj:`Tuple`\[:class:`python:float`, :class:`python:float`], :obj:`Tuple`\[:class:`python:float`, :class:`python:float`, :class:`python:float`], :class:`python: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_size** : :class:`python:int`, default: 12 Font size for the text. **color** : :class:`python:str`, default: "white" Color of the text. **\*\*kwargs** : :class:`python:dict` Additional keyword arguments passed to Plotly's annotation. :Returns: :class:`python:dict` Plotly annotation representing the added text. .. !! processed by numpydoc !! .. py:method:: add_labels(points: Union[List, Any], labels: List[str], font_size: int = 12, point_size: float = 5.0, **kwargs) -> Any Add labels at 3D point locations. :Parameters: **points** : :obj:`Union`\[:obj:`List`, :obj:`Any`] Points where labels should be placed. **labels** : :obj:`List`\[:class:`python:str`] List of label strings to display at each point. **font_size** : :class:`python:int`, default: 12 Font size for the labels. **point_size** : :class:`python:float`, default: 5.0 Size of the point markers shown with labels. **\*\*kwargs** : :class:`python:dict` Additional keyword arguments. :Returns: :obj:`Any` Plotly trace representing the labels. .. !! processed by numpydoc !! .. py:method:: clear() -> None Clear all traces from the figure. .. !! processed by numpydoc !!