Skip to content

Commit 292e8f3

Browse files
authored
Merge pull request matplotlib#26072 from efiring/pcolormesh_masked
Pcolormesh with Gouraud shading: masked arrays
2 parents 3b30f47 + 4971311 commit 292e8f3

File tree

7 files changed

+5528
-19684
lines changed

7 files changed

+5528
-19684
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,8 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
697697
@_log_if_debug_on
698698
def draw_gouraud_triangles(self, gc, points, colors, trans):
699699
assert len(points) == len(colors)
700+
if len(points) == 0:
701+
return
700702
assert points.ndim == 3
701703
assert points.shape[1] == 3
702704
assert points.shape[2] == 2

lib/matplotlib/collections.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,10 @@ def _convert_mesh_to_triangles(self, coordinates):
20982098
], axis=2).reshape((-1, 3, 2))
20992099

21002100
c = self.get_facecolor().reshape((*coordinates.shape[:2], 4))
2101+
z = self.get_array()
2102+
mask = z.mask if np.ma.is_masked(z) else None
2103+
if mask is not None:
2104+
c[mask, 3] = np.nan
21012105
c_a = c[:-1, :-1]
21022106
c_b = c[:-1, 1:]
21032107
c_c = c[1:, 1:]
@@ -2109,8 +2113,8 @@ def _convert_mesh_to_triangles(self, coordinates):
21092113
c_c, c_d, c_center,
21102114
c_d, c_a, c_center,
21112115
], axis=2).reshape((-1, 3, 4))
2112-
2113-
return triangles, colors
2116+
tmask = np.isnan(colors[..., 2, 3])
2117+
return triangles[~tmask], colors[~tmask]
21142118

21152119
@artist.allow_rasterization
21162120
def draw(self, renderer):
Binary file not shown.
Loading

0 commit comments

Comments
 (0)