Skip to content

Commit b741db8

Browse files
committed
Pcolormesh with Gouraud shading: masked arrays
Closes matplotlib#8802. Fixes bug in backend_ps with zero-triangle gouraud inputs. Adds a test for this, and for valid gouraud cases with masking.
1 parent dcb8180 commit b741db8

File tree

7 files changed

+5526
-19684
lines changed

7 files changed

+5526
-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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,8 @@ 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+
mask = c[..., 3] == 0
2102+
c[mask, 3] = np.nan
21012103
c_a = c[:-1, :-1]
21022104
c_b = c[:-1, 1:]
21032105
c_c = c[1:, 1:]
@@ -2109,8 +2111,8 @@ def _convert_mesh_to_triangles(self, coordinates):
21092111
c_c, c_d, c_center,
21102112
c_d, c_a, c_center,
21112113
], axis=2).reshape((-1, 3, 4))
2112-
2113-
return triangles, colors
2114+
mask = np.isnan(colors[..., 2, 3])
2115+
return triangles[~mask], colors[~mask]
21142116

21152117
@artist.allow_rasterization
21162118
def draw(self, renderer):
Binary file not shown.
-37.8 KB
Loading

0 commit comments

Comments
 (0)