Skip to content

Commit 0274a2a

Browse files
authored
Fix support for show_axes and scalar bar title for plot_contour (#263)
* Fix support for show_axes and scalar bar title for plot_contour * Refactor scalar bar title gestion for plot_contour, as well as add_field to minimize duplicate code
1 parent 8597724 commit 0274a2a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

ansys/dpf/core/plotter.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, **kwargs):
7474

7575
def add_mesh(self, meshed_region, **kwargs):
7676

77-
self._set_scalar_bar_title(kwargs)
77+
kwargs = self._set_scalar_bar_title(kwargs)
7878

7979
# Set defaults for PyDPF
8080
kwargs.setdefault("show_edges", True)
@@ -131,24 +131,10 @@ def add_field(self, field, meshed_region=None, show_max=False, show_min=False,
131131
label_text_size=30, label_point_size=20, **kwargs):
132132
# Get the field name
133133
name = field.name.split("_")[0]
134-
# Import pyvista
135-
try:
136-
import pyvista as pv
137-
except ModuleNotFoundError:
138-
raise ModuleNotFoundError(
139-
"To use plotting capabilities, please install pyvista "
140-
"with :\n pip install pyvista>=0.24.0"
141-
)
142-
pv_version = pv.__version__
143-
version_to_reach = '0.30.0'
144-
meet_ver = meets_version(pv_version, version_to_reach)
145-
if meet_ver:
146-
# use scalar_bar_args
147-
scalar_bar_args = {'title': name}
148-
kwargs.setdefault("scalar_bar_args", scalar_bar_args)
149-
else:
150-
# use stitle
151-
kwargs.setdefault("stitle", name)
134+
kwargs.setdefault("stitle", name)
135+
136+
kwargs = self._set_scalar_bar_title(kwargs)
137+
152138
kwargs.setdefault("show_edges", True)
153139
kwargs.setdefault("nan_color", "grey")
154140

@@ -291,6 +277,7 @@ def _set_scalar_bar_title(self, kwargs):
291277
else:
292278
if self._plotter.scalar_bar.GetTitle() is None:
293279
kwargs.setdefault("stitle", stitle)
280+
return kwargs
294281

295282

296283
class DpfPlotter:
@@ -716,7 +703,15 @@ def plot_contour(
716703
# add meshes
717704
kwargs.setdefault("show_edges", True)
718705
kwargs.setdefault("nan_color", "grey")
706+
707+
# Set the scalar bar title
719708
kwargs.setdefault("stitle", name)
709+
kwargs = self._internal_plotter._set_scalar_bar_title(kwargs)
710+
711+
# show axes
712+
show_axes = kwargs.pop("show_axes", None)
713+
if show_axes:
714+
self._internal_plotter._plotter.add_axes()
720715

721716
text = kwargs.pop('text', None)
722717
if text is not None:

0 commit comments

Comments
 (0)