Skip to content

Commit 0fa4887

Browse files
custom title for mesh.plot(field) (#131)
* Update plotter.py adding recognition of "text" in kwargs for contour_plot, adding a title on the lower_edge using pyvista.Plotter.add_text * Add test_plot_fields_on_mesh_scoping_title Add test_plot_fields_on_mesh_scoping_title to test the additional "text" argument for custom titles with mesh.plot(field) * Update test_plotter.py Remove blanks on line 210 to avoid flake8 error on build
1 parent dae9c73 commit 0fa4887

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

ansys/dpf/core/plotter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ def plot_contour(
271271
kwargs.setdefault("show_edges", True)
272272
kwargs.setdefault("nan_color", "grey")
273273
kwargs.setdefault("stitle", name)
274+
text = kwargs.pop('text', None)
275+
if text is not None:
276+
plotter.add_text(text, position='lower_edge')
274277
plotter.add_mesh(mesh.grid, scalars=overall_data, **kwargs)
275278

276279
if background is not None:

tests/test_plotter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ def test_plot_fields_on_mesh_scoping(multishells):
208208
mesh.plot(s[0])
209209

210210

211+
@pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista")
212+
def test_plot_fields_on_mesh_scoping_title(multishells):
213+
model = core.Model(multishells)
214+
mesh = model.metadata.meshed_region
215+
stress = model.results.stress()
216+
stress.inputs.requested_location.connect("Nodal")
217+
scoping = core.Scoping()
218+
scoping.location = "Nodal"
219+
l = list(range(0, 400))
220+
l += list(range(1500, 2000))
221+
l += list(range(2200, 2600))
222+
scoping.ids = l
223+
stress.inputs.mesh_scoping.connect(scoping)
224+
s = stress.outputs.fields_container()
225+
mesh.plot(s[0], text="test")
226+
227+
211228
@pytest.mark.skipif(not HAS_PYVISTA, reason="Please install pyvista")
212229
def test_throw_on_several_time_steps(plate_msup):
213230
model = core.Model(plate_msup)

0 commit comments

Comments
 (0)