Skip to content

Commit 54d4eca

Browse files
authored
FieldsContainer.plot (#1375)
* Add FieldsContainer.plot() Signed-off-by: paul.profizi <[email protected]> * Improve docstring Signed-off-by: paul.profizi <[email protected]> * Add a test and make label_space optional Signed-off-by: paul.profizi <[email protected]> --------- Signed-off-by: paul.profizi <[email protected]>
1 parent e0b7883 commit 54d4eca

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/ansys/dpf/core/fields_container.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,34 @@ def get_time_scoping(self):
479479
"""
480480
return self.get_label_scoping("time")
481481

482+
def plot(self, label_space: dict = None, **kwargs):
483+
"""Plots the fields in the FieldsContainer for the given LabelSpace.
484+
Check the labels available for the FieldsContainer with
485+
:func:`~fields_container.FieldsContainer.labels`.
486+
487+
Parameters
488+
----------
489+
label_space:
490+
A dictionary (LabelSpace) of labels of the :class:`FieldsContainer` with associated
491+
values to select for plotting.
492+
This is used to filter the data to plot, for example:
493+
- if ``label_space={'time': 10}``: a single time step (mandatory for transient)
494+
- if ``label_space={'complex': 0, 'part': 12}``: real part of complex data for a part
495+
See :func:`~fields_container.FieldsContainer.get_fields`.
496+
If None is given, it renders all fields available, which may not make sense.
497+
**kwargs:
498+
For more information on accepted keyword arguments, see :func:`~field.Field.plot` and
499+
:class:`~plotter.DpfPlotter`.
500+
"""
501+
from ansys.dpf.core import plotter
502+
plt = plotter.DpfPlotter(**kwargs)
503+
if label_space is None:
504+
label_space = {}
505+
fields = self.get_fields(label_space=label_space)
506+
for f in fields:
507+
plt.add_field(field=f, **kwargs)
508+
plt.show_figure(**kwargs)
509+
482510
def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs):
483511
"""Creates an animation based on the Fields contained in the FieldsContainer.
484512

tests/test_fieldscontainer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,5 +529,5 @@ def test_fields_container_empty_tf_support(server_type):
529529
assert fields_container.time_freq_support == None
530530

531531

532-
if __name__ == "__main__":
533-
test_add_field_by_time_id()
532+
def test_fields_container_plot(server_type, disp_fc):
533+
disp_fc.plot()

0 commit comments

Comments
 (0)