.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01-basic-plotly-examples/plain-usage.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_01-basic-plotly-examples_plain-usage.py: .. _ref_plain_usage_plotly: ================================= Plain usage of the plotly backend ================================= This example shows the plain usage of the Plotly backend in the Visualization Interface Tool to plot different objects, including PyVista meshes, custom objects, and Plotly-specific objects. .. GENERATED FROM PYTHON SOURCE LINES 32-62 .. code-block:: Python from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend from ansys.tools.visualization_interface.types.mesh_object_plot import MeshObjectPlot from ansys.tools.visualization_interface import Plotter import pyvista as pv from plotly.graph_objects import Mesh3d # Create a plotter with the Plotly backend pl = Plotter(backend=PlotlyBackend()) # Create a PyVista mesh mesh = pv.Sphere() # Plot the mesh pl.plot(mesh) # Create a PyVista MultiBlock multi_block = pv.MultiBlock() multi_block.append(pv.Sphere(center=(-1, -1, 0))) multi_block.append(pv.Cube(center=(-1, 1, 0))) # Plot the MultiBlock pl.plot(multi_block) # Display the plotter pl.show() .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 63-65 Now create a custom object ========================== .. GENERATED FROM PYTHON SOURCE LINES 65-88 .. code-block:: Python class CustomObject: def __init__(self): self.name = "CustomObject" self.mesh = pv.Cube(center=(1, 1, 0)) def get_mesh(self): return self.mesh def name(self): return self.name # Create a custom object custom_cube = CustomObject() custom_cube.name = "CustomCube" # Create a MeshObjectPlot instance mesh_object_cube = MeshObjectPlot(custom_cube, custom_cube.get_mesh()) # Plot the custom mesh object pl.plot(mesh_object_cube) .. GENERATED FROM PYTHON SOURCE LINES 89-92 Display the plotter again ========================= Since Plotly is a web-based visualization, we can show the plot again to include the new object. .. GENERATED FROM PYTHON SOURCE LINES 92-96 .. code-block:: Python pl.show() .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 97-99 Add a Plotly Mesh3d object directly =================================== .. GENERATED FROM PYTHON SOURCE LINES 99-125 .. code-block:: Python custom_mesh3d = Mesh3d( x=[0, 1, 2], y=[0, 1, 0], z=[0, 0, 1], i=[0], j=[1], k=[2], color='lightblue', opacity=0.50 ) pl.plot(custom_mesh3d, name="CustomMesh3d") # Show other plotly objects like Scatter3d from plotly.graph_objects import Scatter3d scatter = Scatter3d( x=[0, 1, 2], y=[0, 1, 0], z=[0, 0, 1], mode='markers', marker=dict(size=5, color='red') ) pl.plot(scatter, name="CustomScatter3d") pl.show() .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.085 seconds) .. _sphx_glr_download_examples_01-basic-plotly-examples_plain-usage.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plain-usage.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plain-usage.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plain-usage.zip `