转载:# S1 P. I& Y+ z. d
本文作者:波哥
# @ L1 R7 x& A; a 联系邮箱:916490285@qq.com . M/ a; |* `7 X4 X/ k5 z
7 |' t" z" ^/ b' N8 Y; o
( j/ H6 W4 E# _0 |% Q( H" 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';% 关键陆地文件;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!!');
3 v( m3 {. ^3 ~) H9 X; |
: l% E0 B( z: `- G3 W4 Q' E# O- Q) D3 ]0 |4 A E, h+ h
) m6 X0 y+ {0 f/ {: c" Q B3 q' `- O5 j6 }, j9 l) F1 Q* [
0 T/ x8 B# h1 E( @& b3 O N. U8 v! l
) i! x2 c: W0 {8 g6 y( X
! y8 F: c; [; G; \8 D[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!!');
v/ a, J$ k( g( W
! o( U' ~0 ^. H: w1 q
7 b! _. D+ P/ w, {! v3 h) z2 G4 t% S$ ?
+ [$ x" ?+ z$ K
0 C: R/ ?: }8 Q! j/ L1 k
' L3 v: ?. n9 f! k/ `[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]);
9 f6 i" U+ I3 e( H9 z# a' f% i. |) n; ?
x4 Z( P( u$ D) L& |7 B+ x. F
/ v$ o. o5 m+ z5 @3 \4 R% Z
: K2 p4 T7 L/ x5 ]0 |# a
) H& ]& y3 } b) e1 I获取本文Matlab绘制一张图里多个Colorbar 数据的途径:0 U) s: w( U- W8 t# M; a
, ?) r1 K; W3 u5 C* H! L" r |