MATLAB Answers


hide NaNs in geoshow

Asked by Sagar
on 5 Nov 2015
Latest activity Commented on by Matthew Cooper on 9 Jul 2019
I am plotting some data using geoshow as below: geoshow (yy, xx, data, 'displaytype', 'texturemap'); The 'data' has a lot of NaNs in it and I do not want to show them (or display them as white) in the resulting image, neither in the colorbar (colorbar should not show the white color). The range of data is between 0 and 1.5. I tried using alphadata as below: t = geoshow (yy, xx, data, 'displaytype', 'texturemap'); set(t, 'AlphaData', ~isnan(data)); but I get the error 'value must be numeric'. I looked in the forums and there are not really clean solution to this problem. Could you please provide a nice, clean solution?
Thank you,


Sign in to comment.



2 Answers

Answer by Amy Haskins on 10 Nov 2015

Try using 'DisplayType', 'surface' instead of 'texturemap'. Also try looking at the fourth example on the geoshow doc page "Create Map of Korea and Display NaNs as Transparent".


on 10 Nov 2015
This seems to work well. Thanks!
Munish Sikka on 28 Mar 2018
works for me as well
Darcy Cordell on 24 Nov 2018
This does not work if you are plotting other types of data on the map.
For example, if you are plotting points using
p = geopoint(x,y);
The points will not show up because they will be "below" the surface or something. They are still there, but hiding. Not sure if there is a nice work-around...

Sign in to comment.

Chad Greene
Answer by Chad Greene
on 6 Nov 2015

Hey Sagar,
Yeah, that set AlphaData trick works for imagesc but not for geoshow. You can try to work around it by converting the logical to numeric like this:
set(t, 'AlphaData',double(~isnan(data)));
But I doubt it will work the way you want it to. I tend to avoid using geoshow because I'm never quite sure how it will behave. It decides which plotting function to call based on what you enter, so why not call the plotting function directly? Can you use pcolor, pcolorm or imagesc?


on 10 Nov 2015
Hi Chad, that did not work either. I have also used pcolor but I wanted to use different map projections to make nicer graphics.
For this to work you need to also set 'FaceAlpha' to 'texturemap' which tells geoshow to map the AlphaData values to the FaceAlpha values.

Sign in to comment.