Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/changelog.d/407.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feat(plotly): Link names to hover info
4 changes: 2 additions & 2 deletions examples/01-basic-plotly-examples/plain-usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def name(self):
color='lightblue',
opacity=0.50
)
pl.plot(custom_mesh3d)
pl.plot(custom_mesh3d, name="CustomMesh3d")

# Show other plotly objects like Scatter3d
from plotly.graph_objects import Scatter3d
Expand All @@ -119,6 +119,6 @@ def name(self):
mode='markers',
marker=dict(size=5, color='red')
)
pl.plot(scatter)
pl.plot(scatter, name="CustomScatter3d")

pl.show()
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def plot_iter(self, plotting_list: Iterable[Any]) -> None:
def plot(
self,
plottable_object: Union[PolyData, pv.MultiBlock, MeshObjectPlot, go.Mesh3d],
name: str = None,
**plotting_options
) -> None:
"""Plot a single object using Plotly.
Expand All @@ -154,27 +155,34 @@ def plot(
The object to plot. Can be a PyVista PolyData, MultiBlock, a MeshObjectPlot, or a Plotly Mesh3d.
plotting_options : dict
Additional plotting options.
name : str, optional
Name of the mesh for labeling in Plotly. Overrides the name from MeshObjectPlot if provided.
"""
if isinstance(plottable_object, MeshObjectPlot):
mesh = plottable_object.mesh
name = plottable_object.name if name is None else name
else:
mesh = plottable_object

if isinstance(mesh, (PolyData, pv.MultiBlock)):
mesh_result = self._pv_to_mesh3d(mesh)

# Handle both single mesh and list of meshes
if isinstance(mesh_result, list):
# MultiBlock case - add all meshes
for mesh_3d in mesh_result:
mesh_3d.name = name if name is not None else mesh_3d.name
self._fig.add_trace(mesh_3d)
else:
# Single PolyData case
mesh_result.name = name if name is not None else mesh_result.name
self._fig.add_trace(mesh_result)
elif isinstance(plottable_object, go.Mesh3d):
if name is not None:
plottable_object.name = name
self._fig.add_trace(plottable_object)
else:
# Try in case there is a compatible Plotly object
try:
plottable_object.name = name
self._fig.add_trace(plottable_object)
except Exception:
raise TypeError("Unsupported plottable_object type for PlotlyInterface.")
Expand Down
Loading