diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index 936815d9..861f90ab 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -15,6 +15,7 @@ import numpy as np import pyvista as pv from pyvista import _vtk as vtk +from pyvista.themes import DefaultTheme from tqdm import tqdm from ansys.mapdl.reader import _binary_reader, _reader, elements @@ -60,7 +61,7 @@ def access_bit(data, num): EMAIL_ME = """Please raise an issue at: https://github.com/pyansys/pymapdl-reader/issues -Or email the developer at alexander.kaszynski@ansys.com +Or email the PyAnsys support team at pyansys.support@ansys.com """ np.seterr(divide="ignore", invalid="ignore") @@ -3020,7 +3021,8 @@ def _plot_point_scalars( plotter.add_axes() # set background - plotter.background_color = kwargs.pop("background", None) + theme = DefaultTheme() + theme.background = kwargs.pop("background", None) # remove extra keyword args kwargs.pop("node_components", None) @@ -3034,14 +3036,13 @@ def _plot_point_scalars( # set scalar bar text colors if text_color: - text_color = pv.parse_color(text_color) - plotter.scalar_bar.GetLabelTextProperty().SetColor(text_color) - plotter.scalar_bar.GetAnnotationTextProperty().SetColor(text_color) - plotter.scalar_bar.GetTitleTextProperty().SetColor(text_color) + theme = DefaultTheme() + theme.color = text_color + pv.global_theme.load_theme(theme) # NAN/missing data are white # plotter.renderers[0].SetUseDepthPeeling(1) # <-- for transparency issues - plotter.mapper.GetLookupTable().SetNanColor(1, 1, 1, 1) + theme.nan_color = [1, 1, 1, 1] if cpos: plotter.camera_position = cpos @@ -3120,12 +3121,8 @@ def exit_callback(plotter, RenderWindowInteractor, event): copied_mesh.point_data["Normals"][:] = cached_normals[j] if add_text: - # 2 maps to vtk.vtkCornerAnnotation.UpperLeft - plotter.textActor.SetText( - 2, - "%s\nPhase %.1f Degrees" - % (result_text, (angle * 180 / np.pi)), - ) + phase = angle * 180 / np.pi + plotter.add_text(f"{result_text} \nPhase {phase} Degrees") # at max supported framerate plotter.update(1, force_redraw=True) @@ -3263,7 +3260,8 @@ def _animate_point_scalars( plotter.add_axes() # set background - plotter.background_color = kwargs.pop("background", None) + theme = DefaultTheme() + theme.background = kwargs.pop("background", None) # remove extra keyword args kwargs.pop("node_components", None) @@ -3278,14 +3276,12 @@ def _animate_point_scalars( # set scalar bar text colors if text_color: - text_color = pv.parse_color(text_color) - plotter.scalar_bar.GetLabelTextProperty().SetColor(text_color) - plotter.scalar_bar.GetAnnotationTextProperty().SetColor(text_color) - plotter.scalar_bar.GetTitleTextProperty().SetColor(text_color) + theme.color = text_color + pv.global_theme.load_theme(theme) # NAN/missing data are white # plotter.renderers[0].SetUseDepthPeeling(1) # <-- for transparency issues - plotter.mapper.GetLookupTable().SetNanColor(1, 1, 1, 1) + theme.nan_color = [1, 1, 1, 1] if cpos: plotter.camera_position = cpos @@ -3334,8 +3330,7 @@ def q_callback(): copied_mesh.active_scalars[:] = data if text is not None: - # 2 maps to vtk.vtkCornerAnnotation.UpperLeft - plotter.textActor.SetText(2, text[i]) + plotter.add_text(text[i]) # at max supported framerate plotter.update(1, force_redraw=True) diff --git a/tests/test_rst.py b/tests/test_rst.py index 16616e2f..1df07ae3 100644 --- a/tests/test_rst.py +++ b/tests/test_rst.py @@ -260,6 +260,18 @@ def test_plot_pontoon_nodal_displacement(): ) +@skip_plotting +@pytest.mark.skipif(pontoon is None, reason="Requires example files") +def test_plot_pontoon_nodal_displacement_with_text_color(): + pontoon.plot_nodal_solution( + 0, + show_displacement=True, + overlay_wireframe=True, + off_screen=True, + text_color="k", + ) + + @skip_plotting @pytest.mark.skipif(pontoon is None, reason="Requires example files") def test_plot_pontoon_nodal_displacement():