Contourfm does not display enough colors

2 views (last 30 days)
Hello,
I have to plot satellite data over a map. To do this I am using contourfm but it does not work well since it shows a very low color intervals. I have LAT, LON and Z matrices all of the same size (176x50). I use a my own colormap (CB). Below the code I am running:
LatLim=[35,39];
LonLim=[11,17];
CX1=[140,300];
ax=worldmap(LatLim,LonLim);
contourfm(LAT,LON,Z,CX1(1):(CX1(2)-CX1(1))/size(CB,1):CX1(2),'LineStyle','none');
setm(ax,'FontSize',10);
colormap(CB);
hc=colorbar;
% ylabel(hc,['TB_{',fn{idx}(3:end),'} (K)']);
hc.FontSize=9;
hc.Ticks=CX1(1):(CX1(2)-CX1(1))/size(CB,1):CX1(2);
hc.TickLabels=num2str(hc.Ticks','%.1f');
caxis(CX1);
I do not get any error but this is the image that I get
My data range bewteen 150 and 282 K. I should get something different with many other colors according to the colorbar. Furthermore, in the upper left corner I have no data, while the plot is pink. Any suggestions how to fix this issue? Attached, please find the LAT,LON,Z and CB files. Many thanks.

Accepted Answer

Cris LaPierre
Cris LaPierre on 4 Mar 2022
Edited: Cris LaPierre on 5 Mar 2022
One thing to be aware of is that colors that are below red correspond to spikes, or focused areas of large changes in Z. These do not always show up well in a contour plot.
load vars
surf(LAT,LON,Z,'FaceColor','interp','EdgeColor','interp')
colormap(CB)
Still, I can see what you mean. When I create a contourm plot, I can see areas where the colors should be but are not.
LatLim=[35,39];
LonLim=[11,17];
CX1=[140,300];
figure
worldmap(LatLim,LonLim)
levels = linspace(CX1(1),CX1(2),size(CB,1));
contourm(LAT,LON,Z,levels)
colormap(CB)
caxis(CX1)
I think the issue is related to your data not being sampled regularly (is scattered rather than gridded). This means the corresponding LAT value changes column to column, and the corresponding LON value changes row to row. Were your LAT and LON data gridded in this fashion, then I don't think you would see this issue.
One approach is to use scatteredInterpolant to create a gridded data set. However, this will change how things appear in the areas you do not have data (the data is not 'square' on a map).
F = scatteredInterpolant(LAT(:),LON(:),Z(:));
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
Lat = linspace(LatLim(1),LatLim(2),200);
Lon = linspace(LonLim(1),LonLim(2));
[lonq,latq] = meshgrid(Lon,Lat);
zq = F(latq,lonq);
figure
worldmap(LatLim,LonLim)
contourfm(latq,lonq,zq,levels,'LineStyle','none')
colormap(CB);
hc=colorbar;
hc.Ticks=linspace(CX1(1),CX1(2),size(CB,1)+1);
hc.TickLabels=num2str(hc.Ticks','%.1f');
caxis(CX1);
The fix here, then, might be to do something to the gridded results to exclude areas for which you do not have any data. I played around with inpolygon. By getting the boundary values of the original LAT and LON variables, I can then use inpolygon with the new gridded latq and lonq values to set the values where the data is unknown to nan.
% find the boundaries of the orginal LAT/LON data
X = [LON(:,1);LON(end,:)';flipud(LON(:,end));LON(1,:)'];
Y = [LAT(:,1);LAT(end,:)';flipud(LAT(:,end));LAT(1,:)'];
in = inpolygon(lonq,latq,X,Y);
zq(~in)=nan;
figure
ax=worldmap(LatLim,LonLim);
levels = linspace(CX1(1),CX1(2),size(CB,1));
contourfm(latq,lonq,zq,levels,'LineStyle','none');
setm(ax,'FontSize',10);
colormap(CB);
hc=colorbar;
% ylabel(hc,['TB_{',fn{idx}(3:end),'} (K)']);
hc.FontSize=9;
hc.Ticks=linspace(CX1(1),CX1(2),size(CB,1)+1);
hc.TickLabels=num2str(hc.Ticks','%.1f');
caxis(CX1);
This may actually be better, as you are now only showing data where you have data.
  1 Comment
Leo Pio D'Adderio
Leo Pio D'Adderio on 7 Mar 2022
Cris,
this is very helpful and, above all, it works. When you say:
"I think the issue is related to your data not being sampled regularly (is scattered rather than gridded). This means the corresponding LAT value changes column to column, and the corresponding LON value changes row to row."
you are right, in the sense of I have orbital data (not over a regular grid). But, other data (another channel of the same satellite) have more or less the same sampling and are scattered as well (I attach the data with label "1"). However, when I run my code, I do not get any problem and this is the resulting plot
This is just for a complete view of the problem. Thanks again.

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!