Skip to content

Commit 7ee9a82

Browse files
Merge pull request #345 from robbievanleeuwen/fix-warping-plot
Plot warping function only over section extents
2 parents d482e97 + 4f27933 commit 7ee9a82

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/sectionproperties/analysis/section.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import matplotlib.axes
1414
import matplotlib.patches as mpatches
15+
import matplotlib.tri as tri
1516
import numpy as np
1617
from matplotlib.colors import ListedColormap
1718
from rich.console import Console
@@ -1680,6 +1681,7 @@ def plot_warping_function(
16801681
title: str = "Warping Function",
16811682
level: int = 20,
16821683
cmap: str = "viridis",
1684+
alpha: float = 0.2,
16831685
with_lines: bool = True,
16841686
**kwargs,
16851687
):
@@ -1690,6 +1692,7 @@ def plot_warping_function(
16901692
level: Number of contour levels
16911693
cmap: Colormap
16921694
with_lines: If set to True, contour lines are displayed
1695+
alpha: Transparency of the mesh outlines: :math:`0 \leq \alpha \leq 1`
16931696
kwargs: Passed to :func:`~sectionproperties.post.post.plotting_context`
16941697
16951698
Raises:
@@ -1707,26 +1710,30 @@ def plot_warping_function(
17071710
with post.plotting_context(title=title, **kwargs) as (fig, ax):
17081711
assert ax
17091712

1710-
loc = self.mesh["vertices"]
1713+
# create triangulation
1714+
triang = tri.Triangulation(
1715+
self._mesh_nodes[:, 0],
1716+
self._mesh_nodes[:, 1],
1717+
self._mesh_elements[:, 0:3],
1718+
)
17111719

17121720
if with_lines:
17131721
ax.tricontour(
1714-
loc[:, 0],
1715-
loc[:, 1],
1722+
triang,
17161723
self.section_props.omega,
17171724
colors="k",
17181725
levels=level,
17191726
)
17201727

17211728
ax.tricontourf(
1722-
loc[:, 0],
1723-
loc[:, 1],
1729+
triang,
17241730
self.section_props.omega,
17251731
cmap=cmap,
17261732
levels=level,
17271733
)
1728-
ax.set_xlabel("X")
1729-
ax.set_ylabel("Y")
1734+
1735+
# plot the finite element mesh
1736+
self.plot_mesh(alpha=alpha, materials=False, **dict(kwargs, ax=ax))
17301737

17311738
return ax
17321739

0 commit comments

Comments
 (0)