How to plot a 2D filled colour contour plot depth profile?
13 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a 3D matrix named SALT which is of 90x90x50 size. Here, 90x90 is latitude/longitude information and 50 is salinity informatin in each ocean layer depth. I want to plot an intersected salinity contour profile like this -
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1567214/image.png)
The intersection will go through the middle of the map, or anywhere according to my choice. I have attached the 3D matrix in this question. Can anyone please help me out here?
Any feedback will be greatly appreciated!!
0 个评论
采纳的回答
Voss
2023-12-12
load SALT
s = permute(SALT(35,:,:),[3 2 1]);
contourf(s)
set(gca(),'YDir','reverse')
xlabel('Longitude(?) Index')
ylabel('Depth Index')
title('Salinity Profile at Latitude(?) #35')
ylabel(colorbar(),'Salinity')
2 个评论
Voss
2023-12-12
Yes, you can make a function, but a loop may be good enough:
load SALT
%% Salinity
clr = flipud(parula(15));
clri= interp1(1:1:15,clr,1:0.25:15,'linear');
figure(1),clf;
n = 1;
t = tiledlayout(1,3);
t.TileSpacing = 'tight';
t.Padding = 'compact';
xIdx = 30;
yIdx = 75;
% Plotting
nexttile
contourf(rot90(rot90(SALT(:,:,1))),150,'edgecolor','none'); shading interp;
colormap(gca, clri);
set(gca,'color',[0.55 0.55 0.55]);
line([xIdx, xIdx], [1, 90], 'Color', 'b', 'LineWidth', 4); hold on;
line([1, 90], [yIdx, yIdx], 'Color', 'r', 'LineWidth', 4); hold on;
set(gca, 'GridLineStyle', '-', 'MinorGridLineStyle', ':', 'LineWidth', 3);
box on; set(gca, 'GridLineStyle', '-','LineWidth', 3);
hold on; set(gca, 'Layer', 'top');
xlabel('x-index'); ylabel('y-index')
set(gca,'XTickLabel',[],'YTickLabel',[]);
set(gca,'FontSize', 15)
title('Intersection line on Arctic')
data = {SALT(:,90-xIdx,:) SALT(90-yIdx,:,:)};
names = {'blue' 'red'};
for ii = 1:numel(data)
nexttile
% Extract the salinity profile at the chosen latitude or longitude
salinityProfile = squeeze(data{ii});
salinityProfile =salinityProfile';
salinityProfile = fliplr(salinityProfile);
contourf(salinityProfile,15,'edgecolor','k','linewidth',1.5);
colormap(gca, clri)
set(gca, 'YDir', 'reverse');
set(gca,'color',[0.55 0.55 0.55])
set(gca, 'GridLineStyle', '-', 'MinorGridLineStyle', ':', 'LineWidth', 3);
box on; set(gca, 'GridLineStyle', '-','LineWidth', 3);
hold on; set(gca, 'Layer', 'top');
title(sprintf('Salinity with depth (%s intersect)',names{ii}));
set(gca,'XTickLabel',[],'YTickLabel',[]);
ylabel('Depth (m)');
set(gca,'FontSize', 15)
end
set(gcf, 'Position', [-2348,775,1403,476]);
c = colorbar;
c.FontSize = 15;
c.FontWeight = 'bold';
c.Layout.Tile = 'east';
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!