Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some plot bugs #2537

Merged
merged 12 commits into from
Dec 11, 2023
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
DOCKER_PACKAGE: ghcr.io/ansys/mapdl
DOCKER_IMAGE_VERSION_DOCS_BUILD: v23.1.0
ON_CI: True
PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=10 --reruns 7 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html'
PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=1 --reruns 1 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html'

# Following env vars when changed will "reset" the mentioned cache,
# by changing the cache file name. It is rendered as ...-v%RESET_XXX%-...
Expand Down
2 changes: 1 addition & 1 deletion examples/01-geometry/01-lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
k1 = mapdl.k("", 1, 1, 0)
k2 = mapdl.k("", 0, 1, 0)
lnum = mapdl.larc(k0, k1, k2, 2)
mapdl.lplot(background="w", color="k", line_width=5, cpos="xy")
mapdl.lplot(background="w", color="y", line_width=5, cpos="xy")


###############################################################################
Expand Down
19 changes: 17 additions & 2 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,8 +1755,14 @@ def vplot(
quality of the mesh to display. Varies between 1 (worst)
to 10 (best). Applicable when ``vtk=True``.

show_numbering : bool, optional
Display line and keypoint numbers when ``vtk=True``.
show_volume_numbering : bool, optional
Display volume numbers when ``vtk=True``.

show_area_numbering : bool, optional
Display area numbers when ``vtk=True``.

show_line_numbering : bool, optional
Display line numbers when ``vtk=True``.

**kwargs
See :meth:`ansys.mapdl.core.plotting.general_plotter` for
Expand Down Expand Up @@ -1812,10 +1818,19 @@ def vplot(
)

meshes_ = get_meshes_from_plotter(pl)
center_volumes = pl.center

for each_mesh in meshes_:
each_mesh.cell_data["entity_num"] = int(each_volu)

if show_volume_numbering:
labels.append(
{
"points": np.array(center_volumes),
"labels": [int(each_volu)],
}
)

meshes.extend(meshes_)

meshes = [{"mesh": meshes}]
Expand Down
14 changes: 14 additions & 0 deletions src/ansys/mapdl/core/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@
if background:
plotter.set_background(background)

# Making sure that labels are visible in dark backgrounds
if not text_color and background:
bg = plotter.background_color.float_rgb
# from: https://graphicdesign.stackexchange.com/a/77747/113009
gamma = 2.2
threshold = (
0.2126 * bg[0] ** gamma + 0.7152 * bg[1] ** gamma + 0.0722 * bg[2] ** gamma
> 0.5 * gamma
)
if threshold:
text_color = "black"

Check warning on line 419 in src/ansys/mapdl/core/plotting.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/plotting.py#L419

Added line #L419 was not covered by tests
else:
text_color = "white"

for point in points:
plotter.add_points(
point["points"],
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class myEmptyClass:
)

if _HAS_MATPLOTLIB:
PyMAPDL_cmap: ListedColormap = ListedColormap(MAPDL_colorbar, name="PyMAPDL", N=255)
PyMAPDL_cmap: ListedColormap = ListedColormap(MAPDL_colorbar, name="PyMAPDL")


def get_ansys_colors(N=9):
Expand Down
42 changes: 42 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,3 +885,45 @@ def test_cuadratic_beam(mapdl, cuadratic_beam_problem):
)
is None
)


@pytest.mark.parametrize("background", ["white", "black", "green", "red"])
def test_labels_colors_background(mapdl, make_block, background):
# Test if the labels change color according background
mapdl.nplot(background=background, nnum=True)


def test_vplot_show_volume_numbering(mapdl, make_block):
mapdl.vplot(show_volume_numbering=True)


def test_vplot_area_numbering(mapdl, make_block):
mapdl.vplot(show_area_numbering=True)


def test_vplot_line_numbering(mapdl, make_block):
mapdl.vplot(show_line_numbering=True)


def test_vplot_multi_numbering(mapdl, make_block):
mapdl.vplot(
show_area_numbering=True, show_line_numbering=True, show_volume_numbering=True
)


def test_vplot_color(mapdl, make_block):
mapdl.vplot(color="gray")


def test_vplot_cpos(mapdl, make_block):
mapdl.vplot(cpos="xy")


def test_vplot_multiargs(mapdl, make_block):
mapdl.vplot(
color="gray",
cpos="xy",
show_volume_numbering=True,
show_line_numbering=False,
show_area_numbering=True,
)
6 changes: 5 additions & 1 deletion tests/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
if has_dependency("pyvista"):
from pyvista import Plotter
from pyvista.plotting.renderer import CameraPosition
from ansys.mapdl.core.theme import PyMAPDL_cmap

from ansys.mapdl.core import examples
from ansys.mapdl.core.post import (
Expand Down Expand Up @@ -158,7 +159,10 @@ def test_disp_norm_all(mapdl, static_solve):
@requires("pyvista")
def test_disp_plot(mapdl, static_solve, comp):
assert (
mapdl.post_processing.plot_nodal_displacement(comp, smooth_shading=True) is None
mapdl.post_processing.plot_nodal_displacement(
comp, smooth_shading=True, cmap=PyMAPDL_cmap
)
is None
)


Expand Down
Loading