Why are there missing pixels in my "heat map" plot using pcolorm?

18 views (last 30 days)
I am using pcolorm to produce a map showing annual mean precipitation in part of South America.
I have found that pcolorm commonly shows dropped pixels around the perimeter of the "heat map", as shown in the attached example.
The map projection is Miller. The gridded data (P_Annual) is complete, and the lat, lon limits of the map are equal to the limits of the data.
  4 Comments
Andrew Stevens
Andrew Stevens on 12 Oct 2023
Rather than editing the source code, another approach I have found to this problem is to calculate the projected coordinates and use the regular version of the function (in this case pcolor instead of pcolorm). After you create the map axes, something like this:
[x,y]=projfwd(getm(gca),lat,lon)
pcolor(x,y,yourz)
I have found the mapping toolbox versions of the code to generally be less reliable than their non mapping tbx counterparts.
Mark Brandon
Mark Brandon on 12 Oct 2023
Andrew, Thanks for the suggestion. My experience is similar, in that the mapping functions are less reliable, but they are also more ambitous as well. I have used projected coordinates for before, and yes, one can then use pcolor rather than pcolorm. But I prefer that maps show lat, lon rather than easting, northing for the coordinates. My fix, which involves changing one line in the pcolorm source code, works without any problems. That said, I have to remember to make the edit each time I upgrade matlab.

Sign in to comment.

Answers (2)

Suvansh Arora
Suvansh Arora on 8 Nov 2022
One possible issue is the dimension of variables and I think resolving that will solve your issue.
  • Expected dimensions for “lat” is [121 1].
  • Expected dimensions for “lon” is [61 1].
Please follow the documentation below for more information about the dimensions of “x’, “y” ans and “c” in “pcolor(x, y, c)” function:
  4 Comments
Mark Brandon
Mark Brandon on 9 Nov 2022
Suvansh,
Short summary: My guess is that your suggestion is based on pcolor, but my problem is related to pcolorm.
Do you have a working code where your suggestion above works? The reason I ask is that I tried your suggestion, which involves swapping lon and lat in the coded example above, and I find that pcolorm throw an error, indicating that the arrays have the wrong dimensions.
Warning: Error creating or updating Surface
Error in value of property CData
Array is wrong shape or size
The wording of your reply suggests that you have not tried your suggestion. In addition, it seems that your idea is based on documentation for pcolor, and not for the Mapping Toolbox command pcolorm.
You are right in that pcolor using a meshgrid convention for the reference grids or grid vectors. Your suggestion of reversing lon and lat implies that you are thinking in terms of that convention.
However, pcolorm using an ngrid convention!!
Also keep in mind that my example above does not throw an error, whereas your suggestion does throw an error.
Also note that the definitive documentation for pcolorm is provided in surfm (and also in the surfm code). My comments here are based on that documentation.
Best,
Mark
Suvansh Arora
Suvansh Arora on 11 Nov 2022
I would recommend changing your dataset in a way that aligns to the size requirements of MATLAB modules. However, you are right in pointing out the issue in the “pcolorm” module and will let the concerned team know about this issue.
As you already have a possible workaround to unblock yourself, I am mentioning below some other workarounds that you may try:
  • Reversing “lat” and “lon” in the code reverse.m shows the “heatmap” with changed DMS (degrees minutes seconds).
  • Using “heatmap” requires number of latvalues to be same as the number of columns in P_Annual, please follow the “heatmap.m” for more details.

Sign in to comment.


Mark Brandon
Mark Brandon on 11 Nov 2022
Suvansh,
I regret to say that our discussion is not getting anywhere. You have the idea that the problem I described could be fixed if I use "the size requirements of MATLAB modules". But in fact the convention I am following is the one used by the MATLAB Mapping Toolbox, and my workaround works as well.
The conventional pcolor function does NOT produce a projected map, so your examples using that function are not relevant to this discussion. (As, your heatmap script fails with an error, and your reverse script produces a blank figure.)
What would help this issue is you would let the Matlab team responsible for the Mapping Toolbox that there is a problem with the way their trimming algorithm is working in surfm (see discussion above). The simpliest fix would be to provide a property to in pcolorm, surfm, and surfacem to turn off the trimming algorithm.
Best,
Mark
  2 Comments
Suvansh Arora
Suvansh Arora on 23 Nov 2022
Hello Mark,
I have informed the team responsible for Mapping Toolbox to take care of this issue. However, if you would like to have any further assistance, please contact MathWorks Support through this link: Contact_Us
Suvansh Arora
Suvansh Arora on 21 Dec 2022
Edited: Suvansh Arora on 21 Dec 2022
To display the heatmap without drop in pixels, we can use the 'geoshow' function.
[lat, lon] = ndgrid(lat, lon); % Replace gridVectors with grids
geoshow(lat, lon, P_Annual*365.25e-3,"DisplayType","texturemap");
follow the documentation below for reference: geoshow

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!