Skip to content

Masked pcolormesh is not tested correctly #8802

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

Closed
QuLogic opened this issue Jun 26, 2017 · 6 comments · Fixed by #26072
Closed

Masked pcolormesh is not tested correctly #8802

QuLogic opened this issue Jun 26, 2017 · 6 comments · Fixed by #26072
Assignees
Milestone

Comments

@QuLogic
Copy link
Member

QuLogic commented Jun 26, 2017

The pcolormesh test says that masked colour arrays are supported, but this masked Zm variable is never used in the test. It appears that this has been the case since the test was added.

I'm not sure exactly how the "correct" masked result should look, or I would update this myself. I hope one of the assignees should have some idea what to do here.

@jkseppan
Copy link
Member

jkseppan commented Jun 6, 2019

#14414 added alpha channel support for triangle meshes in the pdf backend, but I think the question remains how masked results pcolormesh results should look. With flat shading the quads with masked vertices are removed but with Gouraud shading the color is interpolated between the data color and the "bad value" color, which defaults to (0,0,0,0) (black but transparent) so the intermediate colors are a blurry grey. I can't think of an application where someone would want the latter result, but as noted in the #14414 discussion, we don't actually know who's using this feature.

@efiring
Copy link
Member

efiring commented Jun 6, 2019

I think that adding Gouraud shading to pcolormesh is fundamentally confusing; I would prefer that it be broken out into its own function. pcolor, pcolormesh, and pcolorfast are all for coloring quadrilaterals with specified boundaries; the colors are not specified at vertices but for regions. Vertices are not masked; quadrilaterals are. Gouraud shading, with colors specified at vertices, is different. It is more closely related to an image than to a pcolormesh.
I suspect that masking should be handled with an algorithm that sets a triangle to the "bad value" color if any vertex is masked. I also suspect we should leave this as low priority unless and until there is evidence that users need it.

@karlwx
Copy link

karlwx commented Jun 8, 2020

I feel I should chime in here since I am actually one of the people using these features. Recently, I've been dealing with a problem with pcolormesh when dealing with masked arrays or transparency. I think it has to do with the interpolation issues mentioned here, but not sure - maybe one of you all can provide some guidance.

I recently posted a question on stackoverflow about this issue, with no response so far. Basically, when using pcolormesh with non-masked arrays or without a transparent colormap, the results are normal. When I plot masked arrays or have transparent colormaps, the plot becomes a bit more noisy and pixelated. I think it comes down to how the colors are interpolated from nan or transparent values (effectively treated the same by matplotlib).

Here are some examples in addition to the stackoverflow article:

First, just a plot of radar reflectivity - no nans and no transparency below 10 on the colormap. This behaves as expected.
pcolormesh_test_normal

My ultimate goal was to produce a plot of radar reflectivity with precip type, which involves 3 separate arrays. To get it all on the same map, I first plot the regular radar (rain), then plot mix, and snow last. To prevent the latter two pcolormesh calls wiping out all the colors from the first, I either have to mask non-frozen precip areas or make the colormaps transparent in the "white" regions. You can see that this produces a more pixelated result in all areas of precipitation (most noticeable around the cutoff between green and white, and better seen in the stackoverflow post):
pcolormesh_test_transparent

I tried using gouraud shading to try to smooth out that mess, but it arguably produces a worse result - it has the weird grey/white boundaries described in this thread:
pcolormesh_test_transparent_gouraud

I tried contourf, but like gourad shading, white boundaries remain. Ideally, there would be a smooth transition between the colors (like the pcolormesh plot, but not noisy). Also, contourf is too slow to be viable operationally, regardless.
contourf_test_transparent

As a note, I need a solution that works with the Agg backend, as the scripts that make these images will be run via cron.

I hope this is helpful, and I would be grateful for any solutions you all can provide!

@tacaswell
Copy link
Member

attn @WeatherGod @dopplershift

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 13, 2023
@efiring
Copy link
Member

efiring commented Apr 14, 2023

@anntzer added image tests for masked arrays, including quadmesh, in #23294 (test_pcolormesh_small)--but only for the ps backend. The unused Zm definition remains in the test_pcolormesh function immediately above. test_pcolormesh_small.eps includes a subplot with gouraud shading showing that the masking is having no effect. So it looks like we still need to:

  • add masking with gouraud shading
  • fix test_pcolormesh or add a new test_pcolormesh_mask.

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label Apr 14, 2023
efiring added a commit to efiring/matplotlib that referenced this issue Jun 4, 2023
efiring added a commit to efiring/matplotlib that referenced this issue Jun 5, 2023
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.
@QuLogic QuLogic modified the milestones: future releases, v3.8.0 Jun 9, 2023
melissawm pushed a commit to melissawm/matplotlib that referenced this issue Jun 15, 2023
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.
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 a pull request may close this issue.

5 participants