How to plot a 2D filled colour contour plot depth profile?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ashfaq Ahmed
el 12 de Dic. de 2023
Comentada: Voss
el 12 de Dic. de 2023
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 -
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 comentarios
Respuesta aceptada
Voss
el 12 de Dic. de 2023
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 comentarios
Voss
el 12 de Dic. de 2023
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';
Más respuestas (0)
Ver también
Categorías
Más información sobre Contour Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!