Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
73337b5
fix: Optional viz dependency
AlejandroFernandezLuces Apr 1, 2025
1bfe70a
chore: adding changelog file 3820.fixed.md [dependabot-skip]
pyansys-ci-bot Apr 1, 2025
4af92af
fix: Change messages
AlejandroFernandezLuces Apr 1, 2025
2f4314e
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 1, 2025
624324a
Merge branch 'main' into fix/optional-visualizer
AlejandroFernandezLuces Apr 1, 2025
22a091f
chore: adding changelog file 3820.fixed.md [dependabot-skip]
pyansys-ci-bot Apr 1, 2025
dd44368
feat: Add decorator, move matplotlib to graphics, partial parameter n…
AlejandroFernandezLuces Apr 2, 2025
765256d
Merge branch 'main' into fix/optional-visualizer
AlejandroFernandezLuces Apr 2, 2025
4c985d4
Apply suggestions from code review
AlejandroFernandezLuces Apr 2, 2025
1d36fb0
feat: Add backend selector
AlejandroFernandezLuces Apr 2, 2025
06a7117
Update src/ansys/mapdl/core/mapdl_core.py
AlejandroFernandezLuces Apr 2, 2025
d6f3846
feat: Add `set_default_backend` method and default pyvista backend
AlejandroFernandezLuces Apr 3, 2025
8a38cff
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 3, 2025
f5844a2
fix: Decorator
AlejandroFernandezLuces Apr 3, 2025
0fec75e
feat: Add new parameter to tests
AlejandroFernandezLuces Apr 3, 2025
1f52384
feat: Change launcher to new Enum
AlejandroFernandezLuces Apr 3, 2025
d4b95c9
fix: Missing vtk=true in examples
AlejandroFernandezLuces Apr 3, 2025
0d5c2fb
fix: CLI input
AlejandroFernandezLuces Apr 3, 2025
e367dd9
fix: Wrong param name
AlejandroFernandezLuces Apr 3, 2025
387a5cc
fix: PR suggestions
AlejandroFernandezLuces Apr 7, 2025
f5556b7
Merge branch 'main' into fix/optional-visualizer
AlejandroFernandezLuces Apr 7, 2025
13798d0
fix: Import
AlejandroFernandezLuces Apr 7, 2025
fbb423a
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 7, 2025
93404ee
fix: Import
AlejandroFernandezLuces Apr 7, 2025
da82c99
fix: Import
AlejandroFernandezLuces Apr 7, 2025
5b0511c
fix: Missing imports
AlejandroFernandezLuces Apr 7, 2025
eed1822
fix: returning to default state after test
germa89 Apr 7, 2025
ec45e05
feat: making sure we return to default state after testing
germa89 Apr 7, 2025
0963041
fix: update import statements
germa89 Apr 7, 2025
e7956ec
fix: update graphics_backend to use GraphicsBackend enum in failing test
germa89 Apr 7, 2025
568fb42
fix: docstrings in post functions and their test
germa89 Apr 7, 2025
c2f0790
fix: capitalization in enum
germa89 Apr 7, 2025
9d382d6
fix: update graphics_backend handling in convert function and tests
germa89 Apr 7, 2025
2ad65a1
fix: add wraps decorator to requires_graphics function so the docstri…
germa89 Apr 7, 2025
ecd4e1f
Merge branch 'main' into fix/optional-visualizer
germa89 Apr 7, 2025
7b0ddcd
test: Add non existent backend
AlejandroFernandezLuces Apr 8, 2025
9956b2d
test: fix cli test
AlejandroFernandezLuces Apr 8, 2025
826375c
Merge branch 'main' into fix/optional-visualizer
germa89 Apr 14, 2025
64d26c6
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Apr 14, 2025
58c9d91
Merge branch 'main' into fix/optional-visualizer
germa89 Apr 14, 2025
34740c4
fix: Add decorator for deprecated param
AlejandroFernandezLuces Apr 14, 2025
7abb577
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 14, 2025
d0028b9
chore: adding changelog file 3820.fixed.md [dependabot-skip]
pyansys-ci-bot Apr 14, 2025
55bc120
fix: Force keyword-only arguments for non-MAPDL arguments in extended…
germa89 Apr 14, 2025
5f017d8
Apply suggestions from code review
AlejandroFernandezLuces Apr 15, 2025
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
1 change: 1 addition & 0 deletions doc/changelog.d/3820.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: Optional graphics dependency
17 changes: 9 additions & 8 deletions doc/source/user_guide/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ transfer the geometry to Python to visualize it:

- :func:`Mapdl.kplot() <ansys.mapdl.core.Mapdl.kplot>`
- :func:`Mapdl.vplot() <ansys.mapdl.core.Mapdl.vplot>`
- :func:`Mapdl.eplot() <ansys.mapdl.core.Mapdl.eplot>`).
- :func:`Mapdl.eplot() <ansys.mapdl.core.Mapdl.eplot>`).

These methods rely on the :class:`ansys.mapdl.core.plotting.visualizer.MapdlPlotter`
method. Combined with the MAPDL geometry commands, you can
Expand Down Expand Up @@ -91,10 +91,10 @@ some element types, performs meshing, and then displays the mesh:
Plotting non-interactively using MAPDL
--------------------------------------
You can also plot using MAPDL's native plotting tools. To use the
native tools, pass ``vtk=False`` when running plotting commands such
native tools, pass ``graphics_backend=GraphicsBackend.MATPLOTLIB`` when running plotting commands such
as the :func:`Mapdl.aplot <ansys.mapdl.core.Mapdl.aplot>` and
:func:`Mapdl.eplot <ansys.mapdl.core.Mapdl.eplot>` methods. Plots are
generated within MAPDL and then shown using
generated within MAPDL and then shown using
`Matplotlib <matplotlib_main_>`_.


Expand Down Expand Up @@ -132,15 +132,16 @@ Each of these creates a Matplotlib figure and pause execution.

.. code:: pycon

>>> mapdl.aplot(vtk=False)
>>> mapdl.lplot(vtk=False)
>>> mapdl.kplot(vtk=False)
>>> from ansys.mapdl.core import GraphicsBackend
>>> mapdl.aplot(graphics_backend=GraphicsBackend.MATPLOTLIB)
>>> mapdl.lplot(graphics_backend=GraphicsBackend.MATPLOTLIB)
>>> mapdl.kplot(graphics_backend=GraphicsBackend.MATPLOTLIB)


.. figure:: ../images/aplot.png
:width: 400pt

Area Plot from MAPDL displayed using
Area Plot from MAPDL displayed using
`Matplotlib <matplotlib_main_>`_


Expand All @@ -149,7 +150,7 @@ For more information on plotting functions, see :ref:`ref_plotting_api`.

Plotting keyword options
------------------------
When ``vtk=True``, which is the default, all MAPDL plotting
When ``graphics_backend=GraphicsBackend.PYVISTA``, which is the default, all MAPDL plotting
methods allow you to enter in additional keyword arguments to better
control the plot. For example, you can automatically generate a
screenshot of an area plot or element plot with this code:
Expand Down
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ dependencies = [
"ansys-math-core>=0.1.2",
"ansys-platform-instancemanagement~=1.0",
"ansys-tools-path>=0.3.1",
"ansys-tools-visualization-interface>=0.2.6",
"click>=8.1.3", # for CLI interface
"grpcio>=1.30.0", # tested up to grpcio==1.35
"matplotlib>=3.0.0", # for colormaps for pyvista
"numpy>=1.14.0,<3.0.0",
"pexpect>=4.8.0 ; platform_system=='Linux'",
"platformdirs>=3.6.0",
Expand Down Expand Up @@ -53,6 +51,18 @@ jupyter = [
"ipywidgets",
]

graphics = [
"ansys-tools-visualization-interface>=0.2.6",
"matplotlib>=3.0.0", # for colormaps for pyvista
]

all = [
"ansys-tools-visualization-interface>=0.2.6",
"matplotlib>=3.0.0", # for colormaps for pyvista
"jupyterlab>=3",
"ipywidgets",
]

tests = [
"ansys-dpf-core==0.10.1",
"ansys-tools-visualization-interface==0.8.3",
Expand Down
16 changes: 15 additions & 1 deletion src/ansys/mapdl/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from enum import Enum

###############################################################################
# Imports
# =======
Expand Down Expand Up @@ -73,7 +75,19 @@
_HAS_PYVISTA: bool = is_installed("pyvista")
_HAS_REQUESTS: bool = is_installed("requests")
_HAS_TQDM: bool = is_installed("tqdm")
_HAS_VISUALIZER: bool = is_installed("ansys.tools.visualization_interface")
_HAS_VISUALIZER: bool = is_installed(
"ansys.tools.visualization_interface"
) and is_installed("matplotlib")


class GraphicsBackend(Enum):
"""Graphics backend for PyMAPDL.

This enum is used to set the graphics backend for PyMAPDL.
"""

PYVISTA: str = "pyvista"
MATPLOTLIB: str = "matplotlib"


# Setup directories
Expand Down
36 changes: 15 additions & 21 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import numpy as np

from ansys.mapdl import core as pymapdl
from ansys.mapdl.core import GraphicsBackend
from ansys.mapdl.core import LOG as logger
from ansys.mapdl.core import _HAS_VISUALIZER
from ansys.mapdl.core.commands import (
Expand Down Expand Up @@ -70,6 +71,7 @@
check_valid_routine,
last_created,
random_string,
requires_graphics,
requires_package,
run_as,
supress_logging,
Expand Down Expand Up @@ -254,7 +256,7 @@ class _MapdlCore(Commands):
def __init__(
self,
loglevel: DEBUG_LEVELS = "DEBUG",
use_vtk: Optional[bool] = None,
graphics_backend: Optional[GraphicsBackend] = None,
log_apdl: Optional[str] = None,
log_file: Union[bool, str] = False,
local: bool = True,
Expand Down Expand Up @@ -283,18 +285,16 @@ def __init__(
self._save_selection_obj = None

if _HAS_VISUALIZER:
if use_vtk is not None: # pragma: no cover
self._use_vtk = use_vtk
if graphics_backend is not None: # pragma: no cover
self._graphics_backend = graphics_backend
else:
self._use_vtk = True
self._graphics_backend = GraphicsBackend.PYVISTA
else: # pragma: no cover
if use_vtk:
if graphics_backend:
raise ModuleNotFoundError(
"Using the keyword argument 'use_vtk' requires having "
"'ansys-tools-visualization_interface' installed."
"Graphic libraries are required to use this class.\n"
"You can install this using `pip install ansys-mapdl-core[graphics]`."
)
else:
self._use_vtk = False

self._log_filehandler = None
self._local: bool = local
Expand Down Expand Up @@ -1035,14 +1035,14 @@ def solution(self) -> "Solution":
return self._solution

@property
def use_vtk(self):
def graphics_backend(self):
"""Returns if using VTK by default or not."""
return self._use_vtk
return self._graphics_backend

@use_vtk.setter
def use_vtk(self, value: bool):
@graphics_backend.setter
def graphics_backend(self, value: GraphicsBackend):
"""Set VTK to be used by default or not."""
self._use_vtk = value
self._graphics_backend = value

@property
@requires_package("ansys.mapdl.reader", softerror=True)
Expand Down Expand Up @@ -1862,16 +1862,10 @@ def __init__(self, parent: "MapdlBase", pixel_res: int) -> None:
self._parent = weakref.ref(parent)
self._pixel_res = pixel_res

@requires_graphics
def __enter__(self) -> None:
self._parent()._log.debug("Entering in 'WithInterativePlotting' mode")

if not self._parent()._has_matplotlib: # pragma: no cover
raise ModuleNotFoundError(
"Install matplotlib to display plots from MAPDL ,"
"from Python. Otherwise, plot with vtk with:\n"
"``vtk=True``"
)

if not self._parent()._store_commands:
if not self._parent()._png_mode:
self._parent().show("PNG", mute=True)
Expand Down
Loading
Loading