.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/01-basic-plotly-examples/customization_api.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_customization_api.py: .. _plotly_customization_api_example: Backend-Agnostic Customization APIs (Plotly) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example demonstrates the backend-agnostic customization APIs with the Plotly backend. The same API calls work with both PyVista and Plotly backends, demonstrating the true backend-agnostic nature of these methods. .. GENERATED FROM PYTHON SOURCE LINES 35-123 .. raw:: html


.. code-block:: Python import pyvista as pv from ansys.tools.visualization_interface import Plotter from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend # Create a plotter using the Plotly backend and add basic geometry. plotter = Plotter(backend=PlotlyBackend()) # Add a sphere - this works fine sphere = pv.Sphere(radius=1.0, center=(0, 0, 0)) plotter.plot(sphere) # Add point markers to highlight specific locations. key_points = [ [1, 0, 0], # Point on X axis [0, 1, 0], # Point on Y axis [0, 0, 1], # Point on Z axis ] plotter.add_points(key_points, color='red', size=10) # Add line segments to show coordinate axes. # X axis x_axis = [[0, 0, 0], [1.5, 0, 0]] plotter.add_lines(x_axis, color='red', width=4.0) # Y axis y_axis = [[0, 0, 0], [0, 1.5, 0]] plotter.add_lines(y_axis, color='green', width=4.0) # Z axis z_axis = [[0, 0, 0], [0, 0, 1.5]] plotter.add_lines(z_axis, color='blue', width=4.0) # Add a plane to show a reference surface. plotter.add_planes( center=(0, 0, 0), normal=(0, 0, 1), i_size=2.5, j_size=2.5, color='lightblue', opacity=0.2 ) # Add text annotations using 2D normalized coordinates (0-1 range). # Scene title at the top center plotter.add_text("Customization API Example", position=(0.5, 0.95), font_size=18, color='black') # Additional labels at the top corners plotter.add_text("Plotly Backend", position=(0.05, 0.95), font_size=12, color='lightblue') plotter.add_text("3D Visualization", position=(0.95, 0.95), font_size=12, color='lightgreen') # Add labels at specific 3D points to annotate key locations in space. label_points = [ [1, 0, 0], # X axis endpoint [0, 1, 0], # Y axis endpoint [0, 0, 1], # Z axis endpoint ] labels = ['X-axis', 'Y-axis', 'Z-axis'] plotter.add_labels(label_points, labels, font_size=16, point_size=8.0) # The clear() method resets the plotter and can be called even after show(). # This allows reusing the same plotter for multiple visualizations. # Uncomment to clear everything added above and start fresh: # plotter.show() # plotter.clear() # plotter.plot(pv.Cube()) # Would show only a cube instead # Display the visualization with all customizations. # Uncomment to show in browser: plotter.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.084 seconds) .. _sphx_glr_download_examples_01-basic-plotly-examples_customization_api.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: customization_api.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: customization_api.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: customization_api.zip `