收藏本站 劰载中...网站公告 | 吾爱海洋论坛交流QQ群:835383472

[Matlab] Matlab全球气温的陆地海洋单独展示和一张图里多个Colorbar

[复制链接]
转载:# o$ t, K: Q! p! l  j1 _- v6 g+ P
本文作者:波哥
4 a& l8 G. z4 ^
工作单位:中国海洋大学海洋与大气学院
联系邮箱:916490285@qq.com

  R; x1 X  b. s+ x- ?+ |3 {4 j0 \$ B& ?. a8 `

/ @0 q9 l6 t: c" y; L, Z; S
[C] 纯文本查看 复制代码
clc;clear;close all
ncdisp 'F:/RMatlab/data20211219/data46/air.mon.mean.nc';%查看气温数据中的变量
file_air='F:/RMatlab/data20211219/data46/air.mon.mean.nc';
lon=double(ncread(file_air,'lon'));% 直接双精度读取;
lat=double(ncread(file_air,'lat'));% 直接双精度读取;
T2_air=double(ncread(file_air,'air'));% 直接双精度读取;
T2_mean=nanmean(T2_air,3);% 对时间求平均
% land.nc
%找出陆地和海洋的经纬度,想画陆地上的气温,就把海洋上的气温设为nan,反之成立;
file_land='F:/RMatlab/data20211219/data46/land.nc';% 关键陆地文件;1代表陆地,0代表海洋;
ncdisp 'F:/RMatlab/data20211219/data46/land.nc'
land=double(ncread(file_land,'land'));
land=land+1;
land(land==2)=0;
T2=T2_mean.*land;
T2(T2==0)=nan;
[xx,yy]=meshgrid(lon,lat);xx=xx';yy=yy';
%%
figure(1);
m_proj('Equidistant','long',[0,360],'lat',[-90,90]);
% m_proj('miller','lon',180,'lat',[-90 90])
m_contourf(xx,yy,T2,50,'linestyle','none')
% m_pcolor(xx,yy,T2)
% shading interp
% h=m_coast('patch',[0.8 0.8 0.8],'edgecolor','none');
hold on;
% m_gshhs_i('patch',[0.6 0.6 0.6],'edgecolor','k');
% m_coast('color',[0 0 0],'linewidth',1);
m_coast('patch',[1 .85 .7]);
m_grid('ytick',[-90:30:90],'xtick',[0:60:360],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
title('海洋气温','fontsize',12);
c=colorbar('eastoutside','ticklength',0);
caxis([-30,30]);
colormap(m_colmap('jet'));
ax = gca;
axpos = ax.Position;
c.Position(3) = 0.5*c.Position(3);
ax.Position = axpos;
cbarrow;
disp('!!OK!!');

; {& g8 v8 a4 Z: @+ c$ V& N- t- g7 O6 q

( Q7 S2 \& Y! a# S& o3 p
da4d25d3514e2d0d58131f2f41efe375.png

  f9 i: `: Q3 O
d8a695e1c5ac9b1ef1837bd02e3f4927.png
" L6 w; F+ V5 Z% D9 ?, J

5 Q3 m9 ?, f% T: C( F* Z  K/ Y

2 q! X/ z$ p7 N; }  f/ z# P" [/ H) y3 }* |. J: _% F

' [4 l, Q0 [- |1 h
[C] 纯文本查看 复制代码
clc;clear;close all
ncdisp 'F:/RMatlab/data20211219/data46/air.mon.mean.nc';%查看气温数据中的变量
file_air='F:/RMatlab/data20211219/data46/air.mon.mean.nc';
lon=double(ncread(file_air,'lon'));% 直接双精度读取;
lat=double(ncread(file_air,'lat'));% 直接双精度读取;
T2_air=double(ncread(file_air,'air'));% 直接双精度读取;
T2_mean=nanmean(T2_air,3);% 对时间求平均
% land.nc
%找出陆地和海洋的经纬度,想画陆地上的气温,就把海洋上的气温设为nan,反之成立;
file_land='F:/RMatlab/data20211219/data46/land.nc';% 关键陆地文件;
ncdisp 'F:/RMatlab/data20211219/data46/land.nc'
land=double(ncread(file_land,'land'));
T2=T2_mean.*land;
T2(T2==0)=nan;
[xx,yy]=meshgrid(lon,lat);xx=xx';yy=yy';
%%
figure(1);
m_proj('Equidistant','long',[0,360],'lat',[-90,90]);
% m_proj('miller','lon',180,'lat',[-90 90])
m_contourf(xx,yy,T2,50,'linestyle','none')
% m_pcolor(xx,yy,T2)
% shading interp
% h=m_coast('patch',[0.8 0.8 0.8],'edgecolor','none');
hold on;
% m_gshhs_i('patch',[0.6 0.6 0.6],'edgecolor','k');
m_coast('color',[0 0 0],'linewidth',1);
% m_coast('patch',[1 .85 .7]);
m_grid('ytick',[-90:30:90],'xtick',[0:60:360],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
title('海洋气温','fontsize',12);
c=colorbar('eastoutside','ticklength',0);
caxis([-30,30]);
colormap(m_colmap('jet'));
ax = gca;
axpos = ax.Position;
c.Position(3) = 0.5*c.Position(3);
ax.Position = axpos;
cbarrow;
disp('!!OK!!');

3 \3 O6 I* D2 n, H0 N4 G
. Q, M' E/ M( Z/ ?

# G1 n9 }/ T( M4 v- g  c
e40871a93df402fad9298e1ff8df3477.png
+ O9 V: E8 V& H  B9 R
4549fcef3ae3f37a87dc540d2f4e17f2.png
" R/ K/ h. n& T2 `$ {

. d) Z# l) ~# P: J3 L+ m8 n0 g! q
2 J9 _7 c5 {* k# \- p
[C] 纯文本查看 复制代码
clc;clear;close all
ncdisp 'F:/RMatlab/data20211219/data46/air.mon.mean.nc';%查看气温数据中的变量
file_air='F:/RMatlab/data20211219/data46/air.mon.mean.nc';
lon=double(ncread(file_air,'lon'));% 直接双精度读取;
lat=double(ncread(file_air,'lat'));% 直接双精度读取;
T2_air=double(ncread(file_air,'air'));% 直接双精度读取;
T2_mean=nanmean(T2_air,3);% 对时间求平均
%找出陆地和海洋的经纬度,想画陆地上的气温,就把海洋上的气温设为nan,反之成立;
file_land='F:/RMatlab/data20211219/data46/land.nc';% 关键陆地文件;1代表陆地,0代表海洋;
ncdisp 'F:/RMatlab/data20211219/data46/land.nc'
land=double(ncread(file_land,'land'));
T2=land.*T2_mean;
T2(T2==0)=nan;
ncdisp 'F:/RMatlab/data20211219/data46/hgt.mon.mean.nc'% 查看位势高度数据中的变量
file_hgt='F:/RMatlab/data20211219/data46/hgt.mon.mean.nc';% 查看海温数据中的变量
hgt=double(ncread(file_hgt,'hgt'));
level=double(ncread(file_hgt,'level'));
hgt=squeeze(nanmean(hgt(:,:,3,:),4));%对时间求平均,并且取850hpa的位势高度场;
file_u='F:/RMatlab/data20211219/data46/uwnd.mon.mean.nc';
file_v='F:/RMatlab/data20211219/data46/vwnd.mon.mean.nc';
u=double(ncread(file_u,'uwnd'));
v=double(ncread(file_v,'vwnd'));
% ncdisp 'slp.mon.mean.nc';%'Sea Level Pressure'
file_slp='F:/RMatlab/data20211219/data46/slp.mon.mean.nc';
slp=double(ncread(file_slp,'slp'));
slp=nanmean(slp,3);
land=land+1;
land(land==2)=0;
slp=slp.*land;
slp(slp==0)=nan;
u=u.*land;
u(u==0)=nan;
v=v.*land;
v(v==0)=nan;
[xx,yy]=meshgrid(lon,lat);xx=xx';yy=yy';
%%
fig_pos = [0.2 0.02 0.53 0.8];
figure(1);
m_proj('Equidistant','long',[0,360],'lat',[-90,90]);
ax1 = axes;
set(ax1,'position',fig_pos);
% m_pcolor(xx,yy,T2);% 陆地气温
m_contourf(xx,yy,T2,100,'linestyle','none')
shading interp
colormap(ax1,'hsv');
ax1_h=colorbar(ax1,'Position',[.07 .1 .02 .55]);
set(get(ax1_h,'Title'),'string','气温','fontsize',12);
caxis([-50 30])% min(min(T2)) max(max(T2))
% m_coast('color',[0 0 0],'linewidth',0.2);
m_coast;
m_grid('ytick',[-90:30:90],'xtick',[0:60:360],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
hold on
ax2 = axes;
set(ax2,'position',fig_pos);
m_contour(xx,yy,slp,50);% 陆地气温,'linestyle','none'
% m_pcolor(xx,yy,slp);% 陆地气温
% shading interp
colormap(ax2,'winter');
caxis([980 1022])% min(min(slp)) max(max(slp))
% m_coast('color',[0 0 0],'linewidth',0.2);
% m_coast;
m_grid('ytick',[-90:30:90],'xtick',[0:60:360],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
ax2_h=colorbar(ax2,'Position',[.75 .15 .02 .6]);
set(get(ax2_h,'Title'),'string','slp','fontsize',12);
% saveas(gca,'两个colorbar3.png')
%%
figure(2);
fig_pos = [0.09 0.15 0.53 0.75];
m_proj('Equidistant','long',[0,360],'lat',[-90,90]);
ax1 = axes;
set(ax1,'position',fig_pos);
m_pcolor(xx,yy,T2);% 陆地高程
shading interp
colormap(ax1,'jet');
caxis([-50 30])
m_coast('patch',[1 .85 .7]);
m_grid('ytick',[-90:30:90],'xtick',[0:60:360],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
% freezeColors
ax2 = axes;
set(ax2,'position',fig_pos);
% m_contourf(lon,lat,sst','linestyle','none','levelstep',.1);
pc = m_contourf(xx,yy,slp,10);% 海表温度
% set(pc,'linestyle','-');
colormap(ax2,'hsv');
caxis([980 1022])% min(min(slp)) max(max(slp))
m_coast('patch',[1 .85 .7]);
m_grid('ytick',[-90:30:90],'xtick',[0:60:360],'tickdir','out','linest','none','fontname','Times','fontsize',12,'linewidth',1.5);
cb1 = colorbar(ax1,'Position',[.65 .15 .02 .6]);
cb2 = colorbar(ax2,'Position',[.74 .15 .02 .6]);
( `; U/ o% j( L/ M
0 g8 g/ t( ?0 r! c

2 L& D5 \0 F" v; T
2088d318801a8778b746a8c3627fa4cb.png

9 b5 T) X( I+ |& I# }. X6 N* K  N3 F1 m+ L, F$ v9 v" }( W+ u

& J* e. ]7 p: y0 U' t* ^8 {7 {获取本文Matlab绘制
一张图里多个Colorbar
数据的途径:

, G- X4 E3 k* O) z2 Z3 h9 }, N7 E
游客,如果您要查看本帖隐藏内容请回复

0 j1 r) n& J# t) F
回复

举报 使用道具

相关帖子

全部回帖
暂无回帖,快来参与回复吧
懒得打字?点击右侧快捷回复 【吾爱海洋论坛发文有奖】
您需要登录后才可以回帖 登录 | 立即注册
大佬陈
活跃在2026-4-7
快速回复 返回顶部 返回列表