Colorbar Causing mismatch in subfigure

2 ビュー (過去 30 日間)
Zihad Azad
Zihad Azad 2019 年 12 月 31 日
コメント済み: Zihad Azad 2019 年 12 月 31 日
I have the folowing subplotting code
clc; clear all;
load zpos2;
load zpos3;% starts from -22nm (z=-204nm) as it stands
A=E';
l=l*1e9;z1=z1*1e9;
i=2;j=1;
h1=subplot(i,j,1);
p=pcolor(l,z1,A*1e15);
colormap(jet(50));
shading interp; % interpolate colors across lines and faces
xlim([770 900]);
ylim([-620 -100]);
set(gca,'Xticklabel',[]);
xticks([750 775 800 825 850 875 900]);
yticks([-526 -426 -326 -226 -126]);
title('(a)', 'FontSize', 16,'units','normalized','position',[.95 .85]); %gotta normalize the units to the figure window
yticklabels({'z=200','z=100','z=0','z=-100','z=-200',});
line([770, 900], [-326, -326], 'Color', 'black','linewidth',2.5,'LineStyle','--');
line([770, 900], [-426, -426], 'Color', 'black','linewidth',2.5,'LineStyle','--');
% line([875, 875], [-620, -100], 'Color', 'black','linewidth',2.5,'LineStyle','--');
set(h1, 'Units', 'normalized');
get(h1, 'Position');
set(h1,'Position',[ 0.18 0.54 0.63 0.4]);
%colorbar setting
c = colorbar;
%labels the colorbar vertically as desired
set(get(c,'label'),'string','Emission (a.u.)');
c.TickLength=.023;
c.Units='normalized';
c.FontSize=23;
h2=subplot(i,j,2);
plot(l,E1(:,2),'-',l,E1(:,3),'--',l,E1(:,4),':',l,E1(:,5),'-.',l,E1(:,6),'.','linewidth',2.5);
xlabel('Wavelength \rm(nm)'), ylabel('Emission \rm(a.u.)');
xlim([770 900]);
% line([875, 875], [-2, 4], 'Color', 'black','linewidth',2.5,'LineStyle','--');
title('(b)', 'FontSize', 16,'units','normalized','position',[.95 .85]);
legend({'z=-200nm','z=-100nm','z=0nm','z=100nm','z=200nm'},'Units','normalized','Position',[0.47 0.33 0.08 0.08],'FontSize',20);
set(h2, 'Units', 'normalized');
get(h2, 'Position')
set(h2,'Position',[ 0.18 0.13 0.63 0.4]);
legend boxoff;
%font properties
FS='Fontsize';
fs=20;
FN='Fontname';
fn='Times New Roman';
set(findall(gcf,'type','axes'),FS,fs,FN,fn);
set(findall(gcf,'type','text'),FS,fs,FN,fn);
set([h1,h2],'box','on');
set([h1,h2],'TickLength',[.011 .011]);
set(gcf,'renderer','painters');
grid off
But the colorbar is causing mismatch, like this:
1.jpg
With the colorbar absent, I get perfect match:
2.jpg
Is there anyway, I can add the colorbar separately after making the match? The files are attached herewith.
P.S: I know that maximizing the window solves this issue. But I need this window size for my paper. So please help

採用された回答

Image Analyst
Image Analyst 2019 年 12 月 31 日
You can move the colorbar:
hcb = colorbar;
hcb.Position(1) = .8 % Move left edge of colorbar.
hcb.Position(3) = .08 % Adjust width of colorbar
Adjust as needed.
  1 件のコメント
Zihad Azad
Zihad Azad 2019 年 12 月 31 日
Thanks a lot. Does it for me

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by