At the moment I have a plot that looks like the attached, with zero values being land.
How can I make the land black in this plot? without affecting the zero values in the data..
Plot using pcolor (not image or similar), mask out the land with NaNs, and set the axis color to black.
If you don't have a specific land mask already defined, you can use inpolygon with a coastline dataset. For example
lat = linspace(-90, 90, 100); lon = linspace(-180, 180, 100); z = peaks(100);
[long, latg] = meshgrid(lon, lat);
C = load('coast'); island = inpolygon(long, latg, C.long, C.lat);
z(island) = NaN; pcolor(long, latg, z); set(gca, 'color', 'k'); shading flat;
The inpolygon call will be a bit slow with a matrix your size, but you should only have to call that once and then can save the mask for later use. I use my inpolygons function instead, and it tends to be faster for tasks like this.
You can change the colormap used to display the image. First obtain the colormap used by:
map = colormap;
then change the color map corresponding to zero to black [0 0 0]
map(1,:) = 0;
then apply the colormap:
If you don't like the black line in the colorbar, you can convert to rgb, like this untested code:
% Create standard colormap customColorMap = jet(256); % Make bottom color be black customColorMap(1,:) = [0,0,0]; % Convert to RGB rgbImage = ind2rgb(indexedImage, customColorMap); % Display imshow(rgbImage); % Show color map, standard one, not custom one colormap(jet(256)); colorbar;
if your data is Z(i,j), where i=1682 and j=3600 then you must have land masking data (contain of 0 and 1), e.g. if land then the value is one and if ocean then the value is zero. Then do this calculation:
for i=1:1682; for j=1:3600; if (land(i,j)==1); Z(i,j) = NaN; else; Z(i,j) = Z(i,j); end; end; end; end;