Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
add-pdf-html-docs-as-assets: true
optional-dependencies-name: 'doc,all'

smoke-tests:
name: Build and Smoke tests
Expand Down Expand Up @@ -132,6 +133,7 @@ jobs:
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}
requires-xvfb: true
optional-dependencies-name: 'tests,all'

- name: Upload PyVista generated images (cache and results)
if: always()
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/378.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feat: Add Plotly as backend
4 changes: 4 additions & 0 deletions examples/01-basic-plotly-examples/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Basic Plotly usage examples
===========================

These examples show how to use the general plotter with Plotly backend included in the Visualization Interface Tool.
130 changes: 130 additions & 0 deletions examples/01-basic-plotly-examples/plain-usage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""
.. _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.
"""

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
#
# code-block:: python
#
# pl.show()

# Now create a custom object
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)

###########################
# Display the plotter again
# =========================
# Since Plotly is a web-based visualization, we can show the plot again to include the new object.
#
# code-block:: python
#
# pl.show()

# Add a Plotly Mesh3d object directly
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)

# 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)



###########################
# Display the plotter again
# =========================
#
# code-block:: python
#
# pl.show()
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ pyvistaqt = [
"pyside6 >= 6.8.0,<7",
"pyvistaqt >= 0.11.1,<1",
]

plotly = [
"plotly >= 6.3.1,<7",
"kaleido >= 1.1.0,<2",
]

all = [
"pyside6 >= 6.8.0,<7",
"pyvistaqt >= 0.11.1,<1",
"plotly >= 6.3.1,<7",
"kaleido >= 1.1.0,<2",
]

tests = [
"pytest==8.4.2",
"pyvista==0.46.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Plotly initialization."""
Loading
Loading