Contourfm does not display enough colors
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Cris LaPierre
2022-3-4
编辑:Cris LaPierre
2022-3-5
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(:));
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!