chaoshu的个人博客分享 http://blog.sciencenet.cn/u/chaoshu

博文

MATLAB给多个子图实现统一的xlabel,ylabel,colorbar

已有 8659 次阅读 2022-3-14 15:29 |个人分类:matlab|系统分类:科研笔记

https://www.ilovematlab.cn/thread-301523-1-1.html

alex0516 发表于 2014-8-13 15:56:14

在Matlab论坛提的该问题,楼下的回答看的逗了;

image.png

image.png

都2022年了,还是没等来这位“王家乐啊 ”的详细教程,索性我来写一个教程吧!先放一张图看看效果;

colorbar、xlabel、ylabel都可以通过下面几句代码实现任意位置的标注。

set(get(h,'title'),'string','TWS (mm)','position',[200 -35],'FontSize',12);

pos=axis(ax4);%取得最后的subpolt的坐标轴的范围,即[xmin xmax ymin ymax] [0 1 0 1]

xlabel('Longitude(°)','FontSize',12, 'Position',[pos(1)-0.5 pos(4)-11.5]);


image.png


%棋盘测试+GPS测点分布

K=40;

J=40;

m2mm=1000;

load('.\gps_site_ad.mat');

load('.\gps_site.mat');

load('.\A_ad.mat');

load('.\A_025.mat');

load('.\bx.mat');

load(fullfile(getenv('IFILES'),'GPSDATA','YunNan.mat'));

Pxy=shaperead(fullfile(getenv('IFILES'),'COASTS/Yunnan-2020','Yunnan-2020.shp'));

XY=[Pxy.X' Pxy.Y'];

tws=zeros(K,J);

x = [97.125 106.875];

y = [29.875 20.125];


bx=bx/1000;

L=laplace(3,K,J);

beta=0.01;

ad=1;


space=0.05;

map_space_x=2*0.05;

map_space_y=0.05;

map_x=(1-2*map_space_x)/2;

map_y=(1-4*map_space_y)/5;


figure

set(gcf,'Position',[100 100 600 600]) %设置图片整体大小,四个参数分别为xmin,ymin,width,height

ax1=subplot(221);

pos1=set(ax1,'Position',[map_space_x 3*map_space_y+3*map_y map_x 2*map_y]); %设置子图1位置

for k=1:K

    for j=1:J

        tws(k,j)=bx((k-1)*J+j)*m2mm;

    end

end

grid_map(x,y,tws,0.8,XY);

title('(a) Box Check 0-350mm','fontsize',10);

set(gca,'xtick',[]);


h=colorbar('horiz'); %在图的下方添加colorbar

h.Limits=[0 350];

set(h,'position',[map_space_x map_space_y+0.5*map_y space+2*map_x 0.1*map_y]);

set(get(h,'title'),'string','TWS (mm)','position',[200 -35],'FontSize',12);


ax2=subplot(222);

pos2=set(ax2,'Position',[map_space_x+map_x+space 3*map_space_y+3*map_y map_x 2*map_y]); %设置子图2位置

A=A_025;

u=A*bx';

TWS=(A'*A+beta*(L'*L))\A'*u;

for k=1:K

    for j=1:J

        tws(k,j)=TWS((k-1)*J+j)*m2mm;

    end

end

grid_map(x,y,tws,ad,XY);

scatter(gps_site(:,1),gps_site(:,2),3,'g','filled');

title('(b) 100 GPS sites random distribution','fontsize',10);

set(gca,'xtick',[]);%关闭x轴文字标注

set(gca,'ytick',[]);%关闭y轴文字标注


ax3=subplot(223);

pos3=set(ax3,'Position',[map_space_x 2*map_space_y+1*map_y map_x 2*map_y]); %设置子图3位置

A=A_ad;

u=A*bx';

TWS=(A'*A+beta*(L'*L))\A'*u;

for k=1:K

    for j=1:J

        tws(k,j)=TWS((k-1)*J+j)*m2mm;

    end

end

grid_map(x,y,tws,ad,XY);

scatter(gps_site_ad(:,1),gps_site_ad(:,2),3,'r','filled');

title('(c) 100 GPS sites even distribution','fontsize',10);


pos=axis;%取得最后的subpolt的坐标轴的范围,即[xmin xmax ymin ymax] [0 1 0 1]

ylabel('Latitude(°)','FontSize',12, 'Position',[pos(1)-1.5 pos(4)+1]);


ax4=subplot(224);

pos4=set(ax4,'Position',[map_space_x+map_x+space 2*map_space_y+1*map_y map_x 2*map_y]); %设置子图1位置

A=[A_025;A_ad];

u=A*bx';

TWS=(A'*A+beta*(L'*L))\A'*u;

for k=1:K

    for j=1:J

        tws(k,j)=TWS((k-1)*J+j)*m2mm;

    end

end

grid_map(x,y,tws,ad,XY);

scatter(gps_site(:,1),gps_site(:,2),3,'g','filled');

scatter(gps_site_ad(:,1),gps_site_ad(:,2),3,'r','filled');

title('(d) 200 GPS sites even+random','fontsize',10);

set(gca,'ytick',[]);

pos=axis(ax4);%取得最后的subpolt的坐标轴的范围,即[xmin xmax ymin ymax] [0 1 0 1]

xlabel('Longitude(°)','FontSize',12, 'Position',[pos(1)-0.5 pos(4)-11.5]);




https://blog.sciencenet.cn/blog-858128-1329364.html

上一篇:makex生成x-file里面观测值为空
下一篇:yawtab错误导致没有生成autcln.cmd.postfit
收藏 IP: 175.189.209.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-23 14:51

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部