Skip to content

Commit 4e1df4c

Browse files
Merge branch 'main' into dependabot/pip/test-dependencies-ca281f1602
2 parents 3390202 + a219be2 commit 4e1df4c

File tree

16 files changed

+638
-24
lines changed

16 files changed

+638
-24
lines changed

.github/workflows/ci_cd.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
with:
9292
python-version: ${{ env.MAIN_PYTHON_VERSION }}
9393
add-pdf-html-docs-as-assets: true
94+
optional-dependencies-name: 'doc,all'
9495

9596
smoke-tests:
9697
name: Build and Smoke tests
@@ -132,6 +133,7 @@ jobs:
132133
with:
133134
python-version: ${{ env.MAIN_PYTHON_VERSION }}
134135
requires-xvfb: true
136+
optional-dependencies-name: 'tests,all'
135137

136138
- name: Upload PyVista generated images (cache and results)
137139
if: always()

doc/changelog.d/378.maintenance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Feat: Add Plotly as backend
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Basic Plotly usage examples
2+
===========================
3+
4+
These examples show how to use the general plotter with Plotly backend included in the Visualization Interface Tool.
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""
23+
.. _ref_plain_usage_plotly:
24+
25+
=================================
26+
Plain usage of the plotly backend
27+
=================================
28+
29+
This example shows the plain usage of the Plotly backend in the Visualization Interface Tool to plot different objects,
30+
including PyVista meshes, custom objects, and Plotly-specific objects.
31+
"""
32+
33+
from ansys.tools.visualization_interface.backends.plotly.plotly_interface import PlotlyBackend
34+
from ansys.tools.visualization_interface.types.mesh_object_plot import MeshObjectPlot
35+
from ansys.tools.visualization_interface import Plotter
36+
import pyvista as pv
37+
from plotly.graph_objects import Mesh3d
38+
39+
40+
# Create a plotter with the Plotly backend
41+
pl = Plotter(backend=PlotlyBackend())
42+
43+
# Create a PyVista mesh
44+
mesh = pv.Sphere()
45+
46+
# Plot the mesh
47+
pl.plot(mesh)
48+
49+
50+
# Create a PyVista MultiBlock
51+
multi_block = pv.MultiBlock()
52+
multi_block.append(pv.Sphere(center=(-1, -1, 0)))
53+
multi_block.append(pv.Cube(center=(-1, 1, 0)))
54+
55+
# Plot the MultiBlock
56+
pl.plot(multi_block)
57+
58+
#####################
59+
# Display the plotter
60+
#
61+
# code-block:: python
62+
#
63+
# pl.show()
64+
65+
# Now create a custom object
66+
class CustomObject:
67+
def __init__(self):
68+
self.name = "CustomObject"
69+
self.mesh = pv.Cube(center=(1, 1, 0))
70+
71+
def get_mesh(self):
72+
return self.mesh
73+
74+
def name(self):
75+
return self.name
76+
77+
78+
# Create a custom object
79+
custom_cube = CustomObject()
80+
custom_cube.name = "CustomCube"
81+
82+
# Create a MeshObjectPlot instance
83+
mesh_object_cube = MeshObjectPlot(custom_cube, custom_cube.get_mesh())
84+
85+
# Plot the custom mesh object
86+
pl.plot(mesh_object_cube)
87+
88+
###########################
89+
# Display the plotter again
90+
# =========================
91+
# Since Plotly is a web-based visualization, we can show the plot again to include the new object.
92+
#
93+
# code-block:: python
94+
#
95+
# pl.show()
96+
97+
# Add a Plotly Mesh3d object directly
98+
custom_mesh3d = Mesh3d(
99+
x=[0, 1, 2],
100+
y=[0, 1, 0],
101+
z=[0, 0, 1],
102+
i=[0],
103+
j=[1],
104+
k=[2],
105+
color='lightblue',
106+
opacity=0.50
107+
)
108+
pl.plot(custom_mesh3d)
109+
110+
# Show other plotly objects like Scatter3d
111+
from plotly.graph_objects import Scatter3d
112+
113+
scatter = Scatter3d(
114+
x=[0, 1, 2],
115+
y=[0, 1, 0],
116+
z=[0, 0, 1],
117+
mode='markers',
118+
marker=dict(size=5, color='red')
119+
)
120+
pl.plot(scatter)
121+
122+
123+
124+
###########################
125+
# Display the plotter again
126+
# =========================
127+
#
128+
# code-block:: python
129+
#
130+
# pl.show()

pyproject.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ pyvistaqt = [
3636
"pyside6 >= 6.8.0,<7",
3737
"pyvistaqt >= 0.11.1,<1",
3838
]
39+
40+
plotly = [
41+
"plotly >= 6.3.1,<7",
42+
"kaleido >= 1.1.0,<2",
43+
]
44+
45+
all = [
46+
"pyside6 >= 6.8.0,<7",
47+
"pyvistaqt >= 0.11.1,<1",
48+
"plotly >= 6.3.1,<7",
49+
"kaleido >= 1.1.0,<2",
50+
]
51+
3952
tests = [
4053
"pytest==8.4.2",
4154
"pyvista==0.46.3",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Plotly initialization."""

0 commit comments

Comments
 (0)