Skip to content
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

Pcolormesh with Gouraud shading: masked arrays #26072

Merged
merged 2 commits into from Jun 9, 2023

Conversation

efiring
Copy link
Member

@efiring efiring commented Jun 4, 2023

Closes #8802.

PR summary

This PR modifies QuadMesh such that with Gouraud shading, masked "color" array data
for any vertex prevents triangles using that vertex from being rendered. This is similar to what
pcolor does. It differs from the pcolormesh non-Gouraud shadings, for which all regions
are rendered, but masked regions are transparent. This PR changes only the Gouraud shading.

A bug in the Gouraud shading for the PS backend is fixed.

Tests are modified to cover that bug fix, to include masked arrays, and to demonstrate Gouraud
shading with the PS backend.

PR checklist

@ksunden
Copy link
Member

ksunden commented Jun 5, 2023

Test failure does appear to be related:

lib/matplotlib/tests/test_axes.py::test_pcolormesh_small[eps]

@tacaswell tacaswell added this to the v3.8.0 milestone Jun 5, 2023
@efiring
Copy link
Member Author

efiring commented Jun 5, 2023

@ksunden Right you are! This turned up a bug in the ps backend, the fix for which was to copy over 2 lines from the pdf backend. The original test image was also displaying incorrect masking behavior for the gouraud case; in that test there are no unmasked triangles, so the correct plot is a blank Axes. With a tiny grid, 3 by 6, the masking ends up having a very different effect in the gouraud case than in the normal pcolormesh case.

The problem is that the test is no longer testing any normal case with the ps backend. I will have to fix that, either with a new test or by modifying an existing test.

Copy link
Contributor

@greglucas greglucas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think this is an improvement, but I do wonder if other people prefer the alpha=0 gouraud shading in some situations and would want a way to get that? It doesn't seem like the old code is even correct for the alpha-blending, but I could see someone wanting the alpha to be smoothly blended towards the zero-corner rather than dropped completely. Maybe we just wait until that request comes in though...

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.
@efiring
Copy link
Member Author

efiring commented Jun 6, 2023

Logically, the best way to handle masking would be to carry the mask information along and use it directly, rather than using alpha=0 as a proxy for a masked point. That would permit the new behavior here--a masked vertex poisons all its triangles--and also allow full RGBA blending, including with alpha=0, on backends that support it. I will try it.

@efiring
Copy link
Member Author

efiring commented Jun 6, 2023

The two failures are unrelated to the PR.

@tacaswell tacaswell merged commit 292e8f3 into matplotlib:main Jun 9, 2023
37 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Masked pcolormesh is not tested correctly
4 participants