Skip to content

Commit 87fbd38

Browse files
committed
Set axis limits using Vertex position and generalize limits setting
1 parent 9f6a9d1 commit 87fbd38

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

mosaic/polypcolor.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,30 @@ def polypcolor(
8181

8282
# for planar periodic plot explicity set the axis limit
8383
if not descriptor.is_spherical and descriptor.x_period:
84-
xmin = float(descriptor.ds.xEdge.min())
85-
xmax = xmin + descriptor.x_period
86-
84+
xmin, xmax = _find_planar_periodic_axis_limits(descriptor, "x")
8785
ax.set_xlim(xmin, xmax)
8886

8987
if not descriptor.is_spherical and descriptor.y_period:
90-
ymin = float(descriptor.ds.yEdge.min())
91-
ymax = ymin + descriptor.y_period
92-
88+
ymin, ymax = _find_planar_periodic_axis_limits(descriptor, "y")
9389
ax.set_ylim(ymin, ymax)
9490

9591
return collection
92+
93+
94+
def _find_planar_periodic_axis_limits(descriptor, coord):
95+
"""Find the correct (tight) axis limits for planar periodic meshes.
96+
"""
97+
98+
edge_min = float(descriptor.ds[f"{coord}Edge"].min())
99+
vertex_min = float(descriptor.ds[f"{coord}Vertex"].min())
100+
101+
# an edge connects two vertices, so a vertices most extreme position should
102+
# always be more extended than an edge's
103+
if vertex_min > edge_min:
104+
max = float(descriptor.ds[f"{coord}Vertex"].max())
105+
min = max - descriptor.__getattribute__(f"{coord}_period")
106+
else:
107+
min = float(descriptor.ds[f"{coord}Vertex"].min())
108+
max = min + descriptor.__getattribute__(f"{coord}_period")
109+
110+
return min, max

0 commit comments

Comments
 (0)