matlab 画海洋三维变量温度盐度三维变量结合图
这图名字也不会取,展示不知单一变量的分布,是个过程机制的解释!
首先放张文献中的图,简单解释下思路:
底部是先画个三维的海图,变量什么都可以。
再加上海岸线和陆地的颜色填充!
在上面在添加一张平面的海图变量也是随便。再给出三维的视图角度view
因此不会取名字!
思路是上述思路:简单给出大框架!没有细的修饰!都可自行实现!
此图两个重点:
第一:下面的底图容易实现:上面的如何添加呢?
答案:
正常画填充图之后的句柄设置z方向的位置,进行上下调节!
['linestyle','none'); ] = contourf(xx,yy,indian_depth,
h.ContourZLevel =55000;
难点二:如何在上面添加海岸线和陆地的填充!
答案:直接给出函数add_coast.m
add_coast(zlevel)
输出参数就是控制展现高度即可!
我重复的图:
主程序:
clear;clc;close all;
% version one----
%%%%¡ª¡ª¡ª¡ª¡ªCode to draw 3D bathymetry¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª
%-------Created by bo,10/10/2021--------------------
clear;clc;close all;
filenm='etopo.nc';
lon=double(ncread(filenm,'lon'));
lat=double(ncread(filenm,'lat'));
indian_depth=double(ncread(filenm,'elevation'));
%
[xx,yy]=meshgrid(lon,lat);
xx=xx';
yy=yy';
%% ---------------------------------------------
indian_depth(indian_depth>0)=nan;
close all;
figure
set(gcf,'position',[50 50 850 850],'color','w')
hold on
surf(xx,yy,indian_depth);
shading interp
axis([aim_area(1,1) aim_area(1,2) aim_area(2,1) aim_area(2,2) -7000 900])
xlabel('Longitude','FontSize',12);
ylabel('Latitude','FontSize',12);
zlabel('Elevation(m)','FontSize',12);
h=colorbar('v');
% read my colormore
i=6;
map1= load(['colormore_',num2str(i),'.txt']);
colormap(map1)
caxis([-6000 0]);% set color range
set(get(h,'ylabel'),'string','Elevation(m)','fontsize',12);
% add the coast;
alt=0;% conctrol the altitude of land.
add_coast(alt)
% add another variable
[~,h] = contourf(xx,yy,indian_depth,'linestyle','none');
h.ContourZLevel =55000;
% add the coast;
alt=55000;% conctrol the altitude of land.
add_coast(alt)
%
view([55 -65 55])% this is adjust the showing view of picture
zlim([-10000 55000])% this is control z range
% set ztick
set(gca,'ztick',[-10000:2500:0],'zticklabel',[-10000:2500:0])
export_fig('three_dimension_variable.jpg','-r300')
函数:
% add_coast
function add_coast(zlevel)
% zlevel to control % conctrol the altitude of land.
% load coast data , you can find it in m_map, if you download it, you can
% use search for to find it.
load('coast_data.mat') ;
% Get nan's
idx = all(isnan(ncst),2);% split according the nan of data.
idr = diff(find([1;diff(idx);1]));
coast_data = mat2cell(ncst,idr(:),size(ncst,2));
for i = 1:length(coast_data)
if any(isnan(coast_data{i}(:,1)))
continue
end
lon = coast_data{i}(:,1);
lat = coast_data{i}(:,2);
fill3(lon,lat,ones(length(coast_data{i}(:,1)),1)*zlevel,[.8 .8 .8]);
hold on
% this function adapt from Forest;
end
函数参考来源:
% 作者:Forest
% 链接:https://zhuanlan.zhihu.com/p/564968738