Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions ansys/dpf/core/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def to_nodal(self):
op.inputs.connect(self)
return op.outputs.field()

def plot(self, notebook=None, shell_layers=None, **kwargs):
def plot(self, shell_layers=None, **kwargs):
"""Plot the field or fields container on the mesh support if it exists.

Warning
Expand All @@ -259,10 +259,6 @@ def plot(self, notebook=None, shell_layers=None, **kwargs):

Parameters
----------
notebook : bool, optional
Whether the plotting is in the notebook as
a static image or is a dynamic plot outside of the
notebook. The default is ``None``.
shell_layers : shell_layers, optional
Enum used to set the shell layers if the model to plot
contains shell elements. The default is ``None``.
Expand All @@ -271,7 +267,7 @@ def plot(self, notebook=None, shell_layers=None, **kwargs):
arguments, see ``help(pyvista.plot)``.
"""
pl = Plotter(self.meshed_region, **kwargs)
return pl.plot_contour(self, notebook, shell_layers, **kwargs)
return pl.plot_contour(self, shell_layers, **kwargs)

def resize(self, nentities, datasize):
"""Allocate memory.
Expand Down
17 changes: 1 addition & 16 deletions ansys/dpf/core/meshed_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,7 @@ def grid(self):
def plot(
self,
field_or_fields_container=None,
notebook=None,
shell_layers=None,
off_screen=None,
show_axes=True,
**kwargs
):
"""Plot the field or fields container on the mesh.
Expand All @@ -380,16 +377,8 @@ def plot(
----------
field_or_fields_container : dpf.core.Field or dpf.core.FieldsContainer
Field or fields container to plot. The default is ``None``.
notebook : bool, optional
Whether the plotting in the notebook is 2D or 3D. The default is
``None``, in which case the plotting is 2D.
shell_layers : core.shell_layers, optional
Enum used to set the shell layers if the model to plot contains shell elements.
off_screen : bool, optional
Whether to render the plot off screen, which is useful for automated screenshots.
The default is "None", in which case the plot renders off screen.
show_axes : bool, optional
Whether to show a VTK axes widget. The default is ``True``.
**kwargs : optional
Additional keyword arguments for the plotter. For additional keyword
arguments, see ``help(pyvista.plot)``.
Expand All @@ -408,15 +397,11 @@ def plot(
"""
if field_or_fields_container is not None:
pl = Plotter(self, **kwargs)
return pl.plot_contour(field_or_fields_container, notebook,
shell_layers, off_screen, show_axes, **kwargs)
return pl.plot_contour(field_or_fields_container, shell_layers, **kwargs)

# otherwise, simply plot the mesh
kwargs["off_screen"] = off_screen
kwargs["notebook"] = notebook
pl = DpfPlotter(**kwargs)
pl.add_mesh(self, **kwargs)
kwargs["show_axes"] = show_axes
return pl.show_figure(**kwargs)

def deep_copy(self, server=None):
Expand Down
41 changes: 10 additions & 31 deletions ansys/dpf/core/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, **kwargs):
)
# Filter kwargs
kwargs_in = _sort_supported_kwargs(
bound_method=pv.Plotter,
bound_method=pv.Plotter.__init__,
**kwargs)
# Initiate pyvista Plotter
self._plotter = pv.Plotter(**kwargs_in)
Expand Down Expand Up @@ -601,10 +601,7 @@ def plot_chart(fields_container, off_screen=False, screenshot=None):
def plot_contour(
self,
field_or_fields_container,
notebook=None,
shell_layers=None,
off_screen=None,
show_axes=True,
meshed_region=None,
**kwargs
):
Expand All @@ -617,20 +614,9 @@ def plot_contour(
----------
field_or_fields_container : dpf.core.Field or dpf.core.FieldsContainer
Field or field container that contains the result to plot.
notebook : bool, optional
Whether to plot a static image within an iPython notebook
if available. The default is `None`, in which case an attempt is
made to plot a static imaage within an iPython notebook. When ``False``,
a plot external to the notebook is generated with an interactive window.
When ``True``, a plot is always generated within a notebook.
shell_layers : core.shell_layers, optional
Enum used to set the shell layers if the model to plot
contains shell elements.
off_screen : bool, optional
Whether to render off screen, which is useful for automated
screenshots. The default is ``None``.
show_axes : bool, optional
Whether to show a VTK axes widget. The default is ``True``.
**kwargs : optional
Additional keyword arguments for the plotter. For more information,
see ``help(pyvista.plot)``.
Expand Down Expand Up @@ -726,51 +712,44 @@ def plot_contour(
overall_data[ind] = field.data[mask]

# create the plotter and add the meshes
background = kwargs.pop("background", None)
cpos = kwargs.pop("cpos", None)
return_cpos = kwargs.pop("return_cpos", None)

# plotter = pv.Plotter(notebook=notebook, off_screen=off_screen)
if notebook is not None:
self._internal_plotter._plotter.notebook = notebook
if off_screen is not None:
self._internal_plotter._plotter.off_screen = off_screen

# add meshes
kwargs.setdefault("show_edges", True)
kwargs.setdefault("nan_color", "grey")
kwargs.setdefault("stitle", name)

text = kwargs.pop('text', None)
if text is not None:
self._internal_plotter._plotter.add_text(text, position='lower_edge')
kwargs.pop("title", None)

kwargs_in = _sort_supported_kwargs(
bound_method=self._internal_plotter._plotter.add_mesh,
**kwargs
)
self._internal_plotter._plotter.add_mesh(mesh.grid, scalars=overall_data, **kwargs_in)

background = kwargs.pop("background", None)
if background is not None:
self._internal_plotter._plotter.set_background(background)

cpos = kwargs.pop("cpos", None)
if cpos is not None:
self._internal_plotter._plotter.camera_position = cpos

# show result
if show_axes:
self._internal_plotter._plotter.add_axes()
return_cpos = kwargs.pop("return_cpos", None)
kwargs_in = _sort_supported_kwargs(
bound_method=self._internal_plotter._plotter.show,
**kwargs)
if return_cpos is None:
kwargs_in = _sort_supported_kwargs(
bound_method=self._internal_plotter._plotter.show,
**kwargs)
return self._internal_plotter._plotter.show(**kwargs_in)
else:
import pyvista as pv
pv_version = pv.__version__
version_to_reach = '0.32.0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PProfizi, could you please check that it does not break back the following : #140 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anslpa I did, I found a bug, I fixed it, it should work :)

meet_ver = meets_version(pv_version, version_to_reach)
if meet_ver:
return self._internal_plotter._plotter.show(return_cpos=return_cpos)
return self._internal_plotter._plotter.show(return_cpos=return_cpos, **kwargs_in)
else:
txt = """To use the return_cpos option, please upgrade
your pyvista module with a version higher than """
Expand Down
16 changes: 11 additions & 5 deletions examples/05-plotting/00-basic_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@

from ansys.dpf import core as dpf
from ansys.dpf.core import examples
# from ansys.dpf.core.plotter import plot_chart


# Plot the bare mesh of a model
model = dpf.Model(examples.multishells_rst)
model.plot(color="w", show_edges=True, title='Model', text='Model plot')
# # Additional PyVista kwargs are supported, such as:
model.plot(off_screen=True, screenshot='model_plot.png', title='Model', text='Model plot')
model.plot(off_screen=True, notebook=False, screenshot='model_plot.png',
title='Model', text='Model plot off')

# Notes:
# - To make screenshots, use "screenshot" as well as "notebook=False" if on a Jupyter notebook.
# - The "off_screen" keyword only works when "notebook=False" to prevent the GUI from appearing.


# Plot a field on its supporting mesh (field location must be Elemental or Nodal)
Expand All @@ -27,14 +31,16 @@
field = fc[0]
field.plot(notebook=False, shell_layers=None, show_axes=True, title='Field', text='Field plot')
# # Additional PyVista kwargs are supported, such as:
field.plot(off_screen=True, screenshot='field_plot.png', title='Field', text='Field plot off')
field.plot(off_screen=True, notebook=False, screenshot='field_plot.png',
title='Field', text='Field plot off')
#
# # Alternatively one can plot the MeshedRegion associated to the model
mesh = model.metadata.meshed_region
mesh.plot(field_or_fields_container=None, shell_layers=None, show_axes=True,
title='Mesh fc None', text='Mesh plot')
# Additional PyVista kwargs are supported, such as:
mesh.plot(off_screen=True, screenshot='mesh_plot.png', title='Mesh', text='Mesh plot off')
mesh.plot(off_screen=True, notebook=False, screenshot='mesh_plot.png',
title='Mesh', text='Mesh plot off')
# A fields_container or a specific field can be given to plot on the mesh.
mesh.plot(field_or_fields_container=fc, title='Mesh with fields container', text='Mesh fc plot')
mesh.plot(field_or_fields_container=field, title='Mesh with field', text='Mesh field plot')
Expand All @@ -53,5 +59,5 @@
disp_fc = disp_op.outputs.fields_container()
meshes_cont.plot(disp_fc, title='Meshes Container disp_fc', text='Meshes Container disp_fc plot')
# Additional PyVista kwargs are supported, such as:
meshes_cont.plot(off_screen=True, screenshot='meshes_cont_plot.png',
meshes_cont.plot(off_screen=True, notebook=False, screenshot='meshes_cont_plot.png',
title='Meshes Container', text='Meshes Container plot')