Skip to content
Closed
Show file tree
Hide file tree
Changes from 13 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/4025.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix: adapt new visualizer version
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ all = [

tests = [
"ansys-dpf-core[graphics]==0.13.6",
"ansys-tools-visualization-interface==0.9.2",
"ansys-tools-visualization-interface==0.10.0",
"autopep8==2.3.2",
"matplotlib==3.10.3",
"pandas==2.3.0",
Expand All @@ -86,7 +86,7 @@ doc = [
"ansys-dpf-core[graphics]==0.13.6",
"ansys-mapdl-reader==0.55.1",
"ansys-sphinx-theme==1.5.2",
"ansys-tools-visualization-interface==0.9.2",
"ansys-tools-visualization-interface==0.10.0",
"grpcio==1.73.0",
"imageio-ffmpeg==0.6.0",
"imageio==2.37.0",
Expand Down
116 changes: 102 additions & 14 deletions src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ def kplot(
if graphics_backend is GraphicsBackend.PYVISTA:
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_plotter = kwargs.pop("return_plotter", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", None)
return_cpos = kwargs.pop("return_cpos", None)
pl = kwargs.get("plotter", None)
pl = MapdlPlotter().switch_scene(pl)

Expand All @@ -477,7 +481,12 @@ def kplot(
"the database."
)
pl.plot([], [], [], **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

keypoints = self.geometry.get_keypoints(return_as_array=True)
points = [{"points": keypoints}]
Expand All @@ -488,7 +497,12 @@ def kplot(
{"points": keypoints, "labels": self.geometry.knum.astype(int)}
)
pl.plot([], points, labels, **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

# otherwise, use the legacy plotter
if graphics_backend is GraphicsBackend.MAPDL:
Expand Down Expand Up @@ -560,6 +574,11 @@ def lplot(
from ansys.mapdl.core.plotting.theme import get_ansys_colors
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_plotter = kwargs.pop("return_plotter", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", None)
return_cpos = kwargs.pop("return_cpos", False)

kwargs.setdefault("show_scalar_bar", False)
kwargs.setdefault("title", "MAPDL Line Plot")
if not self.geometry.n_line:
Expand All @@ -568,7 +587,13 @@ def lplot(
)
pl = MapdlPlotter()
pl.plot([], [], [], **kwargs)
return pl.show(**kwargs)

return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

lines = self.geometry.get_lines(return_as_list=True)
meshes = []
Expand Down Expand Up @@ -626,7 +651,13 @@ def lplot(
)
pl = MapdlPlotter()
pl.plot(meshes, [], labels, **kwargs)
return pl.show(**kwargs)
obj = pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)
return obj
else:
with self._enable_interactive_plotting():
return super().lplot(nl1=nl1, nl2=nl2, ninc=ninc, **kwargs)
Expand Down Expand Up @@ -747,14 +778,22 @@ def aplot(
kwargs.setdefault("show_scalar_bar", False)
kwargs.setdefault("title", "MAPDL Area Plot")
kwargs.setdefault("scalar_bar_args", {"title": "Scalar Bar Title"})

return_plotter = kwargs.pop("return_plotter", False)
return_cpos = kwargs.pop("return_cpos", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", None)
if not self.geometry.n_area:
warnings.warn(
"Either no areas have been selected or there is nothing to plot."
)
pl = MapdlPlotter()
pl.plot([], [], [], **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

surfs = self.geometry.get_areas(return_as_list=True, quality=quality)
meshes = []
Expand Down Expand Up @@ -859,7 +898,12 @@ def aplot(
)
pl = MapdlPlotter()
pl.plot(meshes, [], labels, **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)
if graphics_backend is GraphicsBackend.MAPDL:
with self._enable_interactive_plotting():
return super().aplot(
Expand Down Expand Up @@ -943,6 +987,11 @@ def vplot(
if graphics_backend is GraphicsBackend.PYVISTA:
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_plotter = kwargs.pop("return_plotter", False)
return_cpos = kwargs.pop("return_cpos", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", None)

pl = kwargs.get("plotter", None)
pl = MapdlPlotter().switch_scene(pl)

Expand All @@ -953,7 +1002,12 @@ def vplot(
)
pl = MapdlPlotter()
pl.plot([], [], [], **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

# Storing entities selection
with self.save_selection:
Expand All @@ -962,7 +1016,6 @@ def vplot(
points = []
labels = []

return_plotter = kwargs.pop("return_plotter", False)
color_areas = True

for each_volu in volumes:
Expand Down Expand Up @@ -990,7 +1043,12 @@ def vplot(
meshes = [{"mesh": meshes}]

pl.plot(meshes, points, labels, **kwargs)
return pl.show(return_plotter=return_plotter, **kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

elif graphics_backend is GraphicsBackend.MAPDL:
with self._enable_interactive_plotting():
Expand Down Expand Up @@ -1125,14 +1183,23 @@ def nplot(self, nnum="", *, graphics_backend=None, **kwargs):

from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_plotter = kwargs.pop("return_plotter", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", None)
return_cpos = kwargs.pop("return_cpos", False)
pl = kwargs.get("plotter", None)
pl = MapdlPlotter().switch_scene(pl)

kwargs.setdefault("title", "MAPDL Node Plot")
if not self.mesh.n_node:
warnings.warn("There are no nodes to plot.")
pl.plot([], [], [], **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

labels = []
if nnum:
Expand All @@ -1146,7 +1213,13 @@ def nplot(self, nnum="", *, graphics_backend=None, **kwargs):
]
points = [{"points": self.mesh.nodes}]
pl.plot([], points, labels, mapdl=self, **kwargs)
return pl.show(**kwargs)

return pl.show(
return_plotter=return_plotter,
savefig=savefig,
return_cpos=return_cpos,
cpos=cpos,
)

elif graphics_backend is GraphicsBackend.MAPDL:
# otherwise, use the built-in nplot
Expand Down Expand Up @@ -1261,6 +1334,10 @@ def eplot(self, show_node_numbering=False, *, graphics_backend=None, **kwargs):
if graphics_backend is GraphicsBackend.PYVISTA:
from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_plotter = kwargs.pop("return_plotter", False)
cpos = kwargs.pop("cpos", None)
return_cpos = kwargs.pop("return_cpos", False)
savefig = kwargs.pop("savefig", None)
pl = kwargs.get("plotter", None)
pl = MapdlPlotter().switch_scene(pl)
pl.mapdl = self
Expand All @@ -1269,7 +1346,12 @@ def eplot(self, show_node_numbering=False, *, graphics_backend=None, **kwargs):
if not self._mesh.n_elem:
warnings.warn("There are no elements to plot.")
pl.plot([], [], [], mapdl=self, **kwargs)
return pl.show(**kwargs)
return pl.show(
return_plotter=return_plotter,
cpos=cpos,
return_cpos=return_cpos,
savefig=savefig,
)

# TODO: Consider caching the surface
esurf = self.mesh._grid.linear_copy().extract_surface().clean()
Expand All @@ -1292,7 +1374,13 @@ def eplot(self, show_node_numbering=False, *, graphics_backend=None, **kwargs):
mapdl=self,
**kwargs,
)
return pl.show(**kwargs)

return pl.show(
return_plotter=return_plotter,
cpos=cpos,
return_cpos=return_cpos,
savefig=savefig,
)
elif graphics_backend is GraphicsBackend.MAPDL:
# otherwise, use MAPDL plotter
with self._enable_interactive_plotting():
Expand Down
10 changes: 4 additions & 6 deletions src/ansys/mapdl/core/plotting/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,6 @@ def plot(
if title: # Added here to avoid labels overlapping title
self.scene.add_title(title, color=text_color)

if return_cpos and return_plotter:
raise ValueError(
"'return_cpos' and 'return_plotter' cannot be both 'True' at the same time."
)

def switch_scene(self, pl: Union["pv.Plotter", "MapdlPlotter"]) -> "MapdlPlotter":
"""Switches the backend scene to the given plotter.

Expand Down Expand Up @@ -849,6 +844,10 @@ def show(
**kwargs,
) -> None:
"""Show the plotter."""
if return_cpos and return_plotter:
raise ValueError(
"'return_cpos' and 'return_plotter' cannot be both 'True' at the same time."
)

self._off_screen = off_screen
if notebook:
Expand All @@ -864,7 +863,6 @@ def show(
auto_close=False,
window_size=window_size,
screenshot=savefig,
**kwargs,
)
self.scene.screenshot(self._savefig)

Expand Down
23 changes: 21 additions & 2 deletions src/ansys/mapdl/core/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ def _plot_point_scalars(self, scalars, show_node_numbering=False, **kwargs):

from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_cpos = kwargs.pop("return_cpos", False)
return_plotter = kwargs.pop("return_plotter", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", None)

with self._mapdl.save_selection:
mask = self.selected_nodes
nodes_ids = self._mapdl.get_array("NODE", item1="NLIST")
Expand Down Expand Up @@ -665,7 +670,12 @@ def _plot_point_scalars(self, scalars, show_node_numbering=False, **kwargs):
pl = MapdlPlotter()
pl.plot(meshes, [], labels, mapdl=self, **kwargs)

return pl.show(**kwargs)
return pl.show(
return_cpos=return_cpos,
return_plotter=return_plotter,
savefig=savefig,
cpos=cpos,
)

@requires_package("ansys.tools.visualization_interface")
def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs):
Expand All @@ -679,6 +689,10 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs):

from ansys.mapdl.core.plotting.visualizer import MapdlPlotter

return_cpos = kwargs.pop("return_cpos", False)
return_plotter = kwargs.pop("return_plotter", False)
savefig = kwargs.pop("savefig", None)
cpos = kwargs.pop("cpos", False)
with self._mapdl.save_selection:
# Select nodes to avoid segfault
self._mapdl.nsle("s", "all")
Expand Down Expand Up @@ -756,7 +770,12 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs):
]
pl = MapdlPlotter()
pl.plot(meshes, [], labels, mapdl=self, **kwargs)
return pl.show(**kwargs)
return pl.show(
return_cpos=return_cpos,
return_plotter=return_plotter,
savefig=savefig,
cpos=cpos,
)

@property
@supress_logging
Expand Down
Loading