Skip to content

Commit 81a1a5c

Browse files
feat: Improve optional arguments in show
1 parent b8906a7 commit 81a1a5c

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/ansys/tools/visualization_interface/backends/pyvista/pyvista.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ def show(
412412
view_2d: Dict = None,
413413
name_filter: str = None,
414414
dark_mode: bool = False,
415-
**plotting_options,
415+
plotting_options: Optional[Dict[str, Any]] = None,
416+
**show_options: Any,
416417
) -> List[Any]:
417418
"""Plot and show any PyAnsys object.
418419
@@ -431,9 +432,11 @@ def show(
431432
Regular expression with the desired name or names to include in the plotter.
432433
dark_mode : bool, default: False
433434
Whether to use dark mode for the widgets.
434-
**plotting_options : dict, default: None
435+
plotting_options : dict, default: None
435436
Keyword arguments. For allowable keyword arguments, see the
436437
:meth:`Plotter.add_mesh <pyvista.Plotter.add_mesh>` method.
438+
**show_options : Any
439+
Additional keyword arguments for the show method.
437440
438441
Returns
439442
-------
@@ -476,7 +479,7 @@ def show(
476479
# Update all buttons/widgets
477480
[widget.update() for widget in self._widgets]
478481

479-
self.show_plotter(screenshot, **plotting_options)
482+
self.show_plotter(screenshot, **show_options)
480483

481484
picked_objects_list = []
482485
if isinstance(plottable_object, list):
@@ -513,7 +516,17 @@ def show_plotter(self, screenshot: Optional[str] = None, **kwargs) -> None:
513516
visualizer.show()
514517
else:
515518
jupyter_backend = kwargs.pop("jupyter_backend", None)
516-
self.pv_interface.show(screenshot=screenshot, jupyter_backend=jupyter_backend)
519+
try:
520+
self.pv_interface.show(
521+
screenshot=screenshot, jupyter_backend=jupyter_backend,
522+
**kwargs
523+
)
524+
except TypeError as e:
525+
logger.warning(
526+
"There are incompatible keyword arguments in the `show` method. "
527+
"Please check the documentation for the correct usage." + str(e)
528+
)
529+
self.pv_interface.show(screenshot=screenshot, jupyter_backend=jupyter_backend)
517530

518531
pv.OFF_SCREEN = self._pv_off_screen_original
519532

tests/test_generic_plotter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,15 @@ def test_dark_mode():
178178
pl = Plotter()
179179
pl.plot(sphere)
180180
pl.show(dark_mode=True)
181+
182+
183+
def test_plotter_show_mix():
184+
"""Test mixing plot and show methods."""
185+
pl = Plotter()
186+
sphere = pv.Sphere()
187+
sphere1 = pv.Sphere(center=(0, 0, 1))
188+
# Plot
189+
pl.plot(sphere1, opacity=0.5, color="blue")
190+
191+
# Mix plot and show
192+
pl.show(sphere, plotting_options={"show_edges": True}, cpos="xy")

0 commit comments

Comments
 (0)