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

[复制链接]
转载:4 y, M8 [! a6 i0 ^0 S2 C
本文作者:波哥& ?$ s! U1 y. E/ K" O- R
工作单位:中国海洋大学海洋与大气学院
联系邮箱:916490285@qq.com
  W6 _- _2 \, L% n; X* s" G) L

8 x8 X' Q5 t& T  K9 @; E

- @5 G& O/ G! v& v* [; P0 r
[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!!');
+ |4 x, t, H0 P5 s0 f9 L9 ^

, S( ]  ^8 ~' T# m0 ~

& ]# W- h( Q( k1 W
da4d25d3514e2d0d58131f2f41efe375.png
. ~( [. }4 w; n) H
d8a695e1c5ac9b1ef1837bd02e3f4927.png
) s8 `0 h: K5 q/ s$ f! F' T6 @2 H3 F

* H& l6 c( }8 z# `; `

2 s- X) P3 Z3 o2 W  d7 `% S& q! a( s2 Q4 Y7 T0 B: M
  L& \! u5 @0 m6 U  G! ~$ ^9 j
[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!!');
4 F' ^/ O2 N$ W+ h7 V; Z4 ^

; a  q" G' b  o
, K3 ~1 s$ q% @- a6 C) @3 B4 @
e40871a93df402fad9298e1ff8df3477.png

6 C! p# l+ ~% G
4549fcef3ae3f37a87dc540d2f4e17f2.png

' m% p" t8 O2 `9 w2 D( P( ^) u. i5 o1 Q' _7 M6 y( R1 `' o; e* b& L

% L* ?! p5 q1 M4 S4 u
[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]);

; {8 c5 m! U7 R& H3 `
+ C' i) W% k! i" b. y8 m) ]/ @8 d
6 Z% v4 V9 {0 @, s' ^/ t
2088d318801a8778b746a8c3627fa4cb.png
6 ^4 F" q# i+ R' ^' K/ w6 t% L

- p% p; V' S0 n5 I  a

+ [; V1 x9 z0 m6 x; B. S获取本文Matlab绘制
一张图里多个Colorbar
数据的途径:

8 r% x- f2 D5 z
游客,如果您要查看本帖隐藏内容请回复

( r" s" X' ?2 ^; |
回复

举报 使用道具

相关帖子

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