转载:( q+ B% C1 ^3 {# f. B. G0 y" p! V
本文作者:波哥$ ?- H. E" [& E$ j' Z, w
联系邮箱:916490285@qq.com + K: u( D8 a, @, I, Q
) D0 |( T9 f: Q `
4 O O3 Z b, @+ r' F[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!!'); * f7 x2 H+ \' A4 O
6 \) {# x& ]4 Q) \7 }+ p* p: b: \1 ^; ~( e
# G: d! R. G/ o
- u2 Q3 r( e8 h) T7 B, c, H
" Q' {$ d) X; R5 N
9 W e2 s0 h( c5 n7 M4 e9 S. c6 R' O5 h; q2 f
1 b# e( Y; m1 c! a$ [! V5 G$ V[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!!');
* g( Q `; P7 C& Y
4 q9 _/ T' E) u3 q( R
! g3 H* n% f. a* p4 }
; t& x! B) f) X* {( e+ O
; d1 O6 V* K. s; a- J! \
% B; G* m/ C# E: K' P+ I. J7 i# |$ v( H' m1 ]1 }5 ? V7 I) l0 n* 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]);
# a* I8 @( A! E& w( U
, B) y+ ~- k; Y* K9 D A( ^) c8 T( U. B+ M+ Q1 b
" O4 l! L) s T/ I2 f' L+ i+ N2 A$ p% ^4 S
9 C6 ]2 i# @ i7 j5 ?' w0 R' T& \. P I/ q$ P3 g1 ?% H
获取本文Matlab绘制一张图里多个Colorbar 数据的途径:
4 B& w8 t0 L, O6 r$ |! B" Y7 S2 N- z% T* Y) G$ M& T
|