Skip to content

Commit ad04b5a

Browse files
authored
Merge pull request #27 from andrewdnolan/periodic_limits
Tight axis limit for planar pediodic meshes
2 parents 2fc1968 + 87fbd38 commit ad04b5a

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

mosaic/polypcolor.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,35 @@ def polypcolor(
7676

7777
# Update the datalim for this polycollection
7878
limits = collection.get_datalim(ax.transData)
79-
# TODO: account for nodes of patches that lie outside of projection bounds
80-
# (i.e. as a result of patch wrapping at the antimeridian)
8179
ax.update_datalim(limits)
8280
ax.autoscale_view()
8381

82+
# for planar periodic plot explicity set the axis limit
83+
if not descriptor.is_spherical and descriptor.x_period:
84+
xmin, xmax = _find_planar_periodic_axis_limits(descriptor, "x")
85+
ax.set_xlim(xmin, xmax)
86+
87+
if not descriptor.is_spherical and descriptor.y_period:
88+
ymin, ymax = _find_planar_periodic_axis_limits(descriptor, "y")
89+
ax.set_ylim(ymin, ymax)
90+
8491
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)