diff --git a/src/ansys/dpf/core/fields_container.py b/src/ansys/dpf/core/fields_container.py index 276ec6e4b50..7be4842fb0f 100644 --- a/src/ansys/dpf/core/fields_container.py +++ b/src/ansys/dpf/core/fields_container.py @@ -479,6 +479,34 @@ def get_time_scoping(self): """ return self.get_label_scoping("time") + def plot(self, label_space: dict = None, **kwargs): + """Plots the fields in the FieldsContainer for the given LabelSpace. + Check the labels available for the FieldsContainer with + :func:`~fields_container.FieldsContainer.labels`. + + Parameters + ---------- + label_space: + A dictionary (LabelSpace) of labels of the :class:`FieldsContainer` with associated + values to select for plotting. + This is used to filter the data to plot, for example: + - if ``label_space={'time': 10}``: a single time step (mandatory for transient) + - if ``label_space={'complex': 0, 'part': 12}``: real part of complex data for a part + See :func:`~fields_container.FieldsContainer.get_fields`. + If None is given, it renders all fields available, which may not make sense. + **kwargs: + For more information on accepted keyword arguments, see :func:`~field.Field.plot` and + :class:`~plotter.DpfPlotter`. + """ + from ansys.dpf.core import plotter + plt = plotter.DpfPlotter(**kwargs) + if label_space is None: + label_space = {} + fields = self.get_fields(label_space=label_space) + for f in fields: + plt.add_field(field=f, **kwargs) + plt.show_figure(**kwargs) + def animate(self, save_as=None, deform_by=None, scale_factor=1.0, **kwargs): """Creates an animation based on the Fields contained in the FieldsContainer. diff --git a/tests/test_fieldscontainer.py b/tests/test_fieldscontainer.py index 24ac3daacb6..8752cf8985c 100644 --- a/tests/test_fieldscontainer.py +++ b/tests/test_fieldscontainer.py @@ -529,5 +529,5 @@ def test_fields_container_empty_tf_support(server_type): assert fields_container.time_freq_support == None -if __name__ == "__main__": - test_add_field_by_time_id() +def test_fields_container_plot(server_type, disp_fc): + disp_fc.plot()