m_map 實例
1、
clear all
m_proj('ortho','lat', 48,'long',-123');%投影方式,范圍
m_coast('patch','r');%紅色填充
m_grid('linest','-','xticklabels',[],'yticklabels',[]);%標注為空
patch(.55*[-1 1 1 -1],.25*[-1 -1 1 1]-.55,'w');%四個點,白色填充
text(0,-.55,'M\_Map','fontsize',25,'color','b',...
'vertical','middle','horizontal','center');%填充內容,屬性要求,垂直水平居中,斜杠轉義符
set(gcf,'units','inches','position',[2 2 3 3]);%設置圖片大小
set(gcf,'paperposition',[3 16 6 6]);%[left bottom width height].

2.
clear all
m_proj('lambert','long',[-160 -40],'lat',[30 80]);
m_coast('patch',[1 .85 .7]);%填充海岸線
m_elev('contourf',[500:500:6000]);%海深等高線
m_grid('box','fancy','tickdir','in');
colormap(flipud(copper));%翻轉三原色的順序排列,重新畫圖

3、
m_proj('stereographic','lat',90,'long',30,'radius',25);
m_elev('contour',[-3500:1000:-500],'edgecolor','b');
m_grid('xtick',12,'tickdir','out','ytick',[70 80],'linest','-');
m_coast('patch',[.7 .7 .7],'edgecolor','r');

4、
4.1默認的加載形式
clear all
Slongs=[-100 0;-75 25;-5 45; 25 145;45 100;145 295;100 290];
Slats= [ 8 80;-80 8; 8 80;-80 8; 8 80;-80 0; 0 80];
for l=1:7,
m_proj('sinusoidal','long',Slongs(l,:),'lat',Slats(l,:));%分區塊的載入地圖
m_grid;
m_coast;
end;
xlabel('Interrupted Sinusoidal Projection of World Oceans');
% In order to see all the maps we must undo the axis limits set by m_grid calls:
set(gca,'xlimmode','auto','ylimmode','auto');%自動加載所有數據

4.2
clear all
subplot(211);
Slongs=[-100 0;-75 25;-5 45; 25 145;45 100;145 295;100 290];
Slats= [ 8 80;-80 8; 8 80;-80 8; 8 80;-80 0; 0 80];
for l=1:7,
m_proj('sinusoidal','long',Slongs(l,:),'lat',Slats(l,:));
m_grid('fontsize',6,'xticklabels',[],'xtick',[-180:30:360],...%字體尺寸,隱藏坐標,坐標等距離排列
'ytick',[-80:20:80],'yticklabels',[],'linest','-','color',[.9 .9 .9]);%線條形式實線,顏色
m_coast('patch','g');%填充綠色
end;
xlabel('Interrupted Sinusoidal Projection of World Oceans');
% In order to see all the maps we must undo the axis limits set by m_grid calls:
set(gca,'xlimmode','auto','ylimmode','auto');
subplot(212);
Slongs=[-100 43;-75 20; 20 145;43 100;145 295;100 295];
Slats= [ 0 90;-90 0;-90 0; 0 90;-90 0; 0 90];%比上面范圍重疊更多
for l=1:6,
m_proj('mollweide','long',Slongs(l,:),'lat',Slats(l,:));
m_grid('fontsize',6,'xticklabels',[],'xtick',[-180:30:360],...
'ytick',[-80:20:80],'yticklabels',[],'linest','-','color','k');
m_coast('patch',[.6 .6 .6]);
end;
xlabel('Interrupted Mollweide Projection of World Oceans');
set(gca,'xlimmode','auto','ylimmode','auto');%自動加載所有數據范圍

5、
clear all
% Nice looking data
[lon,lat]=meshgrid([-136:2:-114],[36:2:54]);
u=sin(lat/6);%?
v=sin(lon/6);
m_proj('oblique','lat',[56 30],'lon',[-132 -120],'aspect',.8);%注意緯度順序,高緯到低緯,'aspect'長寬比
subplot(121);
m_coast('patch',[.9 .9 .9],'edgecolor','none');
m_grid('tickdir','out','yaxislocation','right',...%邊緣經緯線在外,緯度在右,經度在頂
'xaxislocation','top','xlabeldir','end','ticklen',.05);%邊緣經緯度寬度
hold on;%圖層合並
m_quiver(lon,lat,u,v);%經度,緯度,向東,向北的速度分量,轉化為矢量箭頭
xlabel('Simulated surface winds');
subplot(122);
m_coast('patch',[.9 .9 .9],'edgecolor','none');
m_grid('tickdir','in','yticklabels',[],...
'xticklabels',[],'linestyle','none','ticklen',.02);%經緯線去除
hold on;
[cs,h]=m_contour(lon,lat,sqrt(u.*u+v.*v));%畫出輪廓
clabel(cs,h,'fontsize',10,'Color','red','FontWeight','bold');%標注輪廓,字體,字體大小,顏色
xlabel('Simulated something else');

6、
clear all
% Plot a circular orbit
lon=[-180:180];
lat=atan(tan(60*pi/180)*cos((lon-30)*pi/180))*180/pi;
m_proj('miller','lat',80);%查詢,緯度(-80 80),經度(-180 180)
m_coast('color',[0 .6 0]);
m_line(lon,lat,'linewi',2,'color','r');%線寬,2;顏色
m_grid('linestyle','none','box','fancy','tickdir','in');%沒有網格,邊框相間,
%m_line(lon,lat,'linewi',2,'color','r','linestyle',':');控制線條格式,點畫線還是直線

7、
clear all
m_proj('lambert','lon',[-10 20],'lat',[33 48]);%范圍設置與投影有關系
m_tbase('contourf');%畫5-min數據庫輪廓
m_grid('linestyle','none','tickdir','out','linewidth',3);

沒有安裝terrainbase,所以輪廓很簡陋,這個坑用到的時候再填

8、不同分辨率情況下畫的圖
clear all
% Example showing the default coastline and all of the different resolutions
% of GSHHS coastlines as we zoom in on a section of Prince Edward Island.
clf
axes('position',[0.35 0.6 .37 .37]);%[left bottom width height]
m_proj('albers equal-area','lat',[40 60],'long',[-90 -50],'rect','on');%方形,扇形
m_coast('patch',[0 1 0]);%填充
m_grid('linest','none','linewidth',2,'tickdir','out','xaxisloc','top','yaxisloc','right');
m_text(-69,41,'Standard coastline','color','r','fontweight','bold');%經緯度,內容,格式
axes('position',[.09 .5 .37 .37]);
m_proj('albers equal-area','lat',[40 54],'long',[-80 -55],'rect','on');
m_gshhs_c('patch',[.2 .8 .2]);
m_grid('linest','none','linewidth',2,'tickdir','out','xaxisloc','top');
m_text(-80,52.5,'GSHHS\_C (crude)','color','m','fontweight','bold','fontsize',14);
axes('position',[.13 .2 .37 .37]);
m_proj('albers equal-area','lat',[43 48],'long',[-67 -59],'rect','on');
m_gshhs_l('patch',[.4 .6 .4]);
m_grid('linest','none','linewidth',2,'tickdir','out');
m_text(-66.5,43.5,'GSHHS\_L (low)','color','m','fontweight','bold','fontsize',14);
axes('position',[.35 .05 .37 .37]);
m_proj('albers equal-area','lat',[45.8 47.2],'long',[-64.5 -62],'rect','on');
m_gshhs_i('patch',[.5 .6 .5]);
m_grid('linest','none','linewidth',2,'tickdir','out','yaxisloc','right');
m_text(-64.4,45.9,'GSHHS\_I (intermediate)','color','m','fontweight','bold','fontsize',14);
axes('position',[.55 .23 .37 .37]);
m_proj('albers equal-area','lat',[46.375 46.6],'long',[-64.2 -63.7],'rect','on');
m_gshhs_h('patch',[.6 .6 .6]);
m_grid('linest','none','linewidth',2,'tickdir','out','xaxisloc','top','yaxisloc','right');
m_text(-64.18,46.58,'GSHHS\_H (high)','color','m','fontweight','bold','fontsize',14);
運行出現這樣問題

網站https://www.ngdc.noaa.gov/mgg/shorelines/data/gshhs/oldversions/version1.10/下載

下載version1.10中 gshhs_1.10.zip 文件,將zip文件解壓,把gshhs_*.b 文件復制到 matlab\R2009\toolbox\matlab\m_map\@private 文件夾內。打開m_gshhs_c.m,補全路徑。
FILNAME='D:\MATLAB\toolbox\m_map\private/gshhs_c.b'
同理將所有的m_gshhs_*.m路徑都補充完整。

9、
clear all
m_proj('UTM','long',[-72 -68],'lat',[40 44]);
m_gshhs_i('color','k');
m_grid('box','fancy','tickdir','in');
% fake up a trackline
lons=[-71:.1:-67];
lats=60*cos((lons+115)*pi/180);%軌跡經緯度
dates=datenum(1997,10,23,15,1:41,zeros(1,41));%軌跡時間,1分鍾到41分鍾
m_track(lons,lats,dates,'ticks',0,'times',4,'dates',8,...%刻度間隔,時間間隔4分鍾,日期標簽間隔8分鍾
'clip','off','color','r','orient','upright');%顏色標簽方向

10、范圍環
clear all
m_proj('hammer','clong',170);%縮放范圍
m_grid('xtick',[],'ytick',[],'linestyle','-');
m_coast('patch','g');
m_line(100.5,13.5,'marker','square','color','r');%增加了一個標記點
m_range_ring(100.5,13.5,[1000:1000:15000],'color','b','linewi',2);%范圍,顏色,線寬
xlabel('1000km range rings from Bangkok');%曼谷中心1000km的范圍環

11、
clear all
bndry_lon=[-128.8 -128.8 -128.3 -128 -126.8 -126.6 -128.8];
bndry_lat=[ 49 50.33 50.33 50 49.5 49 49];
clf;
m_proj('lambert','long',[-130 -121.5],'lat',[47 51.5],'rectbox','on');
m_gshhs_i('color','k'); % Coastline...
m_gshhs_i('speckle','color','r'); % with speckle added,斑點添加
m_line(bndry_lon,bndry_lat,'linewi',2,'color','k'); % Area outline ...
m_hatch(bndry_lon,bndry_lat,'single',30,5,'color','k'); % ...with hatching added.斜線,30度,5個單位相距
m_grid('linewi',2,'linest','none','tickdir','out');
title('Speckled Boundaries for nice B&W presentation (best in postscript format)','fontsize',14);
m_text(-128,48,5,{'Pacific','Ocean'},'fontsize',18);

12
clear all
m_proj('miller','lat',[-75 75]);
m_coast('patch',[.7 1 .7],'edgecolor','none');
m_grid('box','fancy','linestyle','none','backcolor',[.9 .9 0.9]);
cities={'Cairo','Washington','Buenos Aires'};
lons=[ 30+2/60 -77-2/60 -58-22/60];
lats=[ 31+21/60 38+53/60 -34-45/60];
for k=1:3,
[range,ln,lt]=m_lldist([-123-6/60 lons(k)],[49+13/60 lats(k)],40);
%是兩個位置之間分40個點,range返回距離,ln經度矩陣,lt緯度矩陣
m_line(ln,lt,'color','r','linewi',2);
m_text(ln(end),lt(end),sprintf('%s - %d km',cities{k},round(range)));
end;
title('Great Circle Routes','fontsize',14,'fontweight','bold');

13、 全球/地區溫度圖
(1)讀取數據
clear all
setup_nctoolbox %調用工具包
tic %計時
%%
nc=ncgeodataset('tmpsfc.gdas.199401.grb2'); %讀文件
tem_1=nc.variables %瀏覽數據類型
%%
a1=nc.geovariable(tem_1(1));%取得數據類型為Temperature_surface的數據
b1=a1.data(1,:,:); %第一個時間點溫度數據
c1=squeeze(b1)-273.16;%刪除單一維度,換為攝氏溫度
%%
a2=nc.geovariable(tem_1(2));%取得數據類型為lat的數據,緯度
b2=a2.data(:,1)%提取數據
%%
a3=nc.geovariable(tem_1(3));%經度
b3=a3.data(:,1)%
%%
a4=nc.geovariable(tem_1(4));%取得數據類型為time的數據
b4=a4.data(:,1)%
%%
save A b2 b3 c1
toc
讀取的是NCEP/CFSR數據,1994年1月的溫度數據。

該數據一共四項。溫度,緯度,經度,時間。

時間數據

經度數據

緯度數據

可以看出該數據集的數據組織形式,經度緯度構成世界地圖,記錄了744個時間點的溫度數據。約等於1小時采集一次數據。
溫度數據

保存為mat格式數據,為畫圖做准備。
(2)畫圖
clear all
load A
[Plg,Plt]=meshgrid(b3',b2');%形成網格
m_proj('hammer-aitoff','clongitude',-150);%投影模式
m_pcolor(Plg,Plt,c1);
shading flat;
colormap('jet');%顏色選擇
hold on;
m_pcolor(Plg-360,Plt,c1);
shading flat; %着色模式
colormap('jet');
m_coast();
m_grid('xaxis','middle');
% h=colorbar('h');
% set(get(h,'title'),'string','1991年1月全球溫度');
c=colorbar('southoutside','fontsize',12)
c.Label.String = '1994年1月全球溫度';
c.Label.FontSize = 15;

(3)找出最大、最小溫度的經緯度
clear all load C Max_col=max(c1);%列最大值 Max_row=max(c1,[],2)%行最大值 Max=max(max(c1)); [x1,y1]=find(c1==max(max(c1)));%x 行,y 列 T_1=Plt(x1,y1)%緯度 T_2=Plg(x1,y1)%經度 Min_col=min(c1);%列最大值 Min_row=min(c1,[],2)%行最大值 Min=min(min(c1)); [x,y]=find(c1==min(min(c1)));%x 行,y 列 T_x=Plt(x,y)%緯度 T_y=Plg(x,y)%經度

可以看出最熱52度,在澳大利亞那塊(142.8123E,23.2610S);最冷-62度,在北極圈那塊(89.9999E,66.3486N)。
(4)中國(地區)溫度圖
clear all
load A
LATLIMS=[3 54];
LONLIMS=[72 134];%選定邊界范圍
[Plg,Plt]=meshgrid(b3',b2');%形成網格
m_proj('lambert','lon',LONLIMS,'lat',LATLIMS);%投影模式
m_pcolor(Plg,Plt,c1);
shading flat;
colormap('jet');%顏色選擇
hold on;
m_pcolor(Plg-360,Plt,c1);
shading flat; %着色模式
colormap('jet');
m_coast();
m_grid('box','fancy','tickdir','in');
% h=colorbar('h');
% set(get(h,'title'),'string','1991年1月全球溫度');
c=colorbar('southoutside','fontsize',12)
c.Label.String = '1994年1月中國溫度';
c.Label.FontSize = 15;

該方法是讀取全球數據,只展示部分
(5)
改進的區域方法,讀取該區域的數據數據,
clear all
setup_nctoolbox %調用工具包
tic %計時
%%
min_lat=115;
max_lat=279;
min_lon=231;
max_lon=430; %區域經緯度范圍,在數據中的位置
%%
nc=ncgeodataset('tmp2m.gdas.199401.grb2'); %讀文件
tem_1=nc.variables %瀏覽數據類型
%%
N1=nc.size(tem_1(1));%讀取數據大小,可以看出數據的組織形式
a1=nc.geovariable(tem_1(1));%取得數據類型為Temperature_surface的數據
b1=a1.data(1,1,min_lat:max_lat,min_lon:max_lon); %第一個時間點溫度數據
c1=squeeze(b1)-273.16;%刪除單一維度,換為攝氏溫度
%%
N2=nc.size(tem_1(2));
a2=nc.geovariable(tem_1(2));%取得數據類型為lat的數據,緯度
b2=a2.data(min_lat:max_lat,1);%提取數據
%%
N3=nc.size(tem_1(3))
a3=nc.geovariable(tem_1(3));%經度
b3=a3.data(min_lon:max_lon,1);%
%%
N4=nc.size(tem_1(4))
a4=nc.geovariable(tem_1(4));%取得數據類型為time的數據
b4=a4.data(:,1);%
%%
N5=nc.size(tem_1(5));%讀取數據大小
a5=nc.geovariable(tem_1(5));%取得數據類型為time的數據
b5=a5.data(:,1);%
%%
save tem b2 b3 c1
toc

clear all
load tem
LATLIMS=[3 54];
LONLIMS=[72 134];%選定邊界范圍
[Plg,Plt]=meshgrid(b3',b2');%形成網格
m_proj('lambert','lon',LONLIMS,'lat',LATLIMS);%投影模式
m_pcolor(Plg,Plt,c1);
shading flat;
colormap('jet');%顏色選擇
hold on;
m_pcolor(Plg-360,Plt,c1);
shading flat; %着色模式
colormap('jet');
m_coast();
m_grid('box','fancy','tickdir','in');
% h=colorbar('h');
% set(get(h,'title'),'string','1991年1月全球溫度');
c=colorbar('southoutside','fontsize',12)
c.Label.String = '1994年1月中國溫度';
c.Label.FontSize = 15;


八、圓形區域的畫圖
1、
clear all
LATLIMS=[14 22];
LONLIMS=[108 118];%南海邊界范圍
m_proj('miller','lon',LONLIMS,'lat',LATLIMS);%投影模式
m_coast('patch',[0.1 0.7 0.4]);%綠色填充
m_grid('box','fancy','tickdir','in');%沒有網格,邊框相間,%m_line(lon,lat,'linewi',2,'color','r','linestyle',':');控制線條格式,點畫線還是直線
lon=112:1:116;
lat=16:1:20;
m_line(lon,lat,'linewi',2,'color','r');%線寬,2;顏色
[X,Y]=m_ll2xy(117,21);
line(X,Y,'marker','.','markersize',24','color','r')%畫點

2、距離
clear all %distance用法 arclen=distance([37,0],[35,0])%返回兩點間的相對球心的角度,以度為單位 d=distance([37,0],[35,0],6371)% [緯度,經度] [緯度,經度] [半徑] D=(arclen/180)*pi*6371 %m_map中函數 dist=m_lldist([0 0],[35 37])%[經度 經度] [緯度 緯度]

3、
clear all
LATLIMS=[14 22];
LONLIMS=[108 118];%南海邊界范圍
m_proj('miller','lon',LONLIMS,'lat',LATLIMS);%投影模式
m_coast('patch',[0.1 0.7 0.4]);%綠色填充
m_grid('box','fancy','tickdir','in');%沒有網格,邊框相間,%m_line(lon,lat,'linewi',2,'color','r','linestyle',':');控制線條格式,點畫線還是直線
load EDH_south_sea_2008
load coordi_south_sea_2008
m_range_ring(114,18,[1e2:1e2:3e2],'linewi',2,'color','b');%紅色300km范圍圓圈
% 矩形點陣
range_lat=4:24;%21N和15N對應的位置下標
range_lon=20:40;%111.5E和116.5E對應的下標
for i=1:length(range_lon)
for j=1:length(range_lat)
[X,Y]=m_ll2xy(lon_south_sea(range_lon(i)),lat_south_sea(range_lat(j)));%化為x,y坐標
line(X,Y,'marker','.','markersize',10,'color','k')%畫點
hold on
end
end
%離散圓
[X0,Y0]=m_ll2xy(114,18);%化為x,y坐標
line(X0,Y0,'marker','.','markersize',15,'color','r');%畫圓心
DIST=m_lldist([114 114],[18 19]);%緯度加1度,增加的距離
R=300;%300km
[X1,Y1]=m_ll2xy(114,18+R/DIST);%找到300km的一個點
r=sqrt((X0-X1)^2+(Y0-Y1)^2);%地圖距離到圖上距離轉換
theta=0:pi/180:2*pi;%360度,360個點。
x=X0+r*cos(theta); %(X0,Y0)圓心
y=Y0+r*sin(theta);
plot(x,y,'.','color','r')

4、pcolor
clear all
n =18;
r = (0:n)'/n;
theta = pi*(-n:n)/n;
X = r*cos(theta);
Y = r*sin(theta);
C = r*cos(2*theta);
pcolor(X,Y,C)
axis equal tight
colorbar
figure
load PCOLOR %南海坐標和波導高度數據
colormap('jet');
shading flat;%平滑方式
gca=pcolor(Plg,Plt,EDH_south_sea)
set(gca, 'LineStyle','none');%去除網格
axis equal tight %按比例展示
colorbar %顏色條

clear all n =6; r = (0:n)'/n;%0到6,半徑上均分的數 theta = pi*(-n:n)/n;%將整個圓分成了13分。 X = r*cos(theta); Y = r*sin(theta); C = r*cos(2*theta); pcolor(X,Y,C) axis equal tight colorbar



