Skip to content

Pcolormesh with Gouraud shading: masked arrays #26072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ def draw_gouraud_triangle(self, gc, points, colors, trans):
@_log_if_debug_on
def draw_gouraud_triangles(self, gc, points, colors, trans):
assert len(points) == len(colors)
if len(points) == 0:
return
assert points.ndim == 3
assert points.shape[1] == 3
assert points.shape[2] == 2
Expand Down
8 changes: 6 additions & 2 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -2098,6 +2098,10 @@ def _convert_mesh_to_triangles(self, coordinates):
], axis=2).reshape((-1, 3, 2))

c = self.get_facecolor().reshape((*coordinates.shape[:2], 4))
z = self.get_array()
mask = z.mask if np.ma.is_masked(z) else None
if mask is not None:
c[mask, 3] = np.nan
c_a = c[:-1, :-1]
c_b = c[:-1, 1:]
c_c = c[1:, 1:]
Expand All @@ -2109,8 +2113,8 @@ def _convert_mesh_to_triangles(self, coordinates):
c_c, c_d, c_center,
c_d, c_a, c_center,
], axis=2).reshape((-1, 3, 4))

return triangles, colors
tmask = np.isnan(colors[..., 2, 3])
return triangles[~tmask], colors[~tmask]

@artist.allow_rasterization
def draw(self, renderer):
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/pcolormesh.pdf
Binary file not shown.
Binary file modified lib/matplotlib/tests/baseline_images/test_axes/pcolormesh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading