转载:4 T' @# }, |4 S) m8 x1 L. j
本文作者:波哥; B1 [% a, D- s, B( |
联系邮箱:916490285@qq.com 4 S: ^* u3 ?& b1 u) S& T. m( w
; o# \$ [( I2 J5 x8 h# E
3 ?: n7 ^3 c6 F2 f w8 T
[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!!');
& h Y6 ~+ Y( l
7 _0 H; [6 G. e; C! W9 d( b! l: S$ N+ k e' J: L
3 u- d m' X- Y, n6 I/ d# L! d
8 j+ V$ O, z' @3 ]' U
2 O; y) C, e+ B3 l O
& f/ l; C4 B) J* n$ j
8 g0 t% M( _/ @) s# L3 x: Q$ [7 _+ x$ J9 Q/ i$ _
[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!!');
/ S2 n, } u! `& {' R
0 q+ g+ A" C0 l% F/ H9 ]
8 X- P* G4 d4 t. `7 k$ n+ h/ U5 r' G! N( P# v) _& M r! R( U
# l7 j/ h3 N# g- j* M w" r# w/ V. |4 E, i9 X: a% |5 h1 A2 A
5 W) P6 r/ }% W
[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]);
% \6 G% @8 z. D1 B
[4 l7 w& r8 Y/ B( M$ e
8 u% w0 q$ O: m7 A& [* @6 @& {. V) D# O- J
* c% f* |$ V+ p8 N
/ K; Q3 z% [: a9 N获取本文Matlab绘制一张图里多个Colorbar 数据的途径:; G& |+ N: u' I+ j
7 F) ?1 Q8 n& y6 I' X0 J |