How to define different color for NaN values than that assigned by colormap in geoshow?
8 views (last 30 days)
Show older comments
Lalit Pal
on 26 Jul 2018
Commented: Francisco Javier Alvial Vásquez
on 6 Oct 2022
I'm trying to create a plot of gridded data using geoshow() and assigned colors to the plot using colormap() command. The data has NaN values for few grid points. The color assigned to these grid point is that of the bottom most strip of colorbar. I want the color of these grid points with NaN to be different (preferably white) from the color assigned by colormap(). The code, sample data and plot generated with code have been attached. I have tried different ways to do it but couldn't succeed. Please help me to find a way out. Thanks is advance.
%----- Code used for generating spatial plots---
latlim = ([19 23.75]);
lonlim = ([80 87]);
lat = latlim(1):0.25:latlim(2);
lon = lonlim(1):0.25:lonlim(2);
[lat, lon] = meshgrid(lat, lon);
Param = csvread('Reg_PCPTOT.csv');
Shapeloc = 'Mahanadi_basin.shp';
[S, a] = shaperead(Shapeloc, 'UseGeoCoords', true);
figure('Color','white','PaperPosition', [0.25 0.25 16 16], 'PaperUnits', 'inches');
ax = worldmap(latlim, lonlim);
t = geoshow(lat, lon, Param, 'displaytype', 'texturemap');
colormap('jet');
geoshow([S.Lat], [S.Lon],'LineWidth',2,'Color','black');
setm(ax,'FontName','calibrilight','FontSize',14);
title('pcptot','FontSize',18, 'FontWeight','bold');
hcb = colorbar('eastoutside');
print('Reg_PCPTOT','-dtiff','-r300')
2 Comments
Accepted Answer
KSSV
on 26 Jul 2018
Edited: KSSV
on 26 Jul 2018
t = geoshow(lat, lon, Param, 'displaytype', 'surface');
Use surface as displaytype instead of texturemap.
OR
t = geoshow(lat, lon, Param, 'displaytype', 'texturemap');
colormap('jet');
t.AlphaDataMapping = 'none'; % interpet alpha values as transparency values
t.FaceAlpha = 'texturemap'; % Indicate that the transparency can be different each pixel
alpha(t,double(~isnan(Param))) %
3 Comments
More Answers (0)
See Also
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!