Misalignment plot with several axes

Dear all,
I have the following code that gives me a group of subplots.
for k = 1:N
CellSELpercentil{k} = eval(string(SELtimepercentil(k)));
M=CellSELpercentil{k};
ax1=axes;
subplot(2,3,k,ax1);
imagesc(ax1,km2deg(Xv),km2deg(Yv),M);
h=colorbar(ax1,'southoutside');
ylabel(h,'Sound Exposure Level (dB)');
set(gca,'YDir','normal');
clear title
title(strcat('SEL\_', listofpercentis(k)));
xlabel('LONGITUDE');
ylabel('LATITUDE');
axis tight;
clear title
ax2=axes;
subplot(2,3,k,ax2);
contourf(ax2,km2deg(lon_km),km2deg(lat_km),elevation', [-5 -5],'w','facecolor','w');
ax3=axes;
subplot(2,3,k,ax3);
c2=contourf(ax3,km2deg(lon_km),km2deg(lat_km),elevation', [0 0],'facecolor',[0.5 0.5 0.5]);
linkaxes([ax1,ax2,ax3]);
ax2.Visible = 'off';
ax2.XTick = [];
ax2.YTick = [];
ax3.Visible = 'off';
ax3.XTick = [];
ax3.YTick = [];
ax2.Visible = 'on';
ax2.Visible = 'off';
ax3.Visible = 'on';
ax3.Visible = 'off';
axes(ax1); axis equal;
axes(ax2); axis equal;
axes(ax3); axis equal;
hold on;
ax1.XGrid = 'on';
ax1.YGrid = 'on';
ax1.GridColor = [1, 1, 1]; % [R, G, B]
hold on; contourf(km2deg(lon_km),km2deg(lat_km),elevation', [-50 -50],'w','ShowText','on','facecolor','none'); %linha dos 50m
hold on; contourf(km2deg(lon_km),km2deg(lat_km),elevation', [-100 -100],'w','ShowText','on','facecolor','none'); %linha dos 100m
hold on; contourf(km2deg(lon_km),km2deg(lat_km),elevation', [-250 -250],'w','ShowText','on','facecolor','none'); %linha dos 250m
hold on; contourf(km2deg(lon_km),km2deg(lat_km),elevation', [-1000 -1000],'w','ShowText','on','facecolor','none'); %linha dos 1000m
portugal=text(deg2km(-8.6),deg2km(38.3),'Portugal','FontSize',20); %Portugal Setubal
set(portugal,'Rotation',90);
setubal=text(deg2km(-9.0),deg2km(38.55),'Setubal','FontSize',14); %Portugal Sines
caxis(ax1,[120 180]);
hold off
end
set(gcf,'WindowState','maximized')
However everything works fine, but when I had the colorbar (line 8) the axis kind of get displaced and I get the following plots.
Do you have any idea of how to get it working properly?
Thank you in advance

 採用された回答

Simon Chan
Simon Chan 2022 年 2 月 1 日

0 投票

When you create a colorbar, the figure region is shifted upwards and hence it automatically adjust the positions of ax1.
In order to align the other axis to ax1, add these two lines somewhere after defining ax2 and ax3
ax2.Position = ax1.Position;
ax3.Position = ax1.Position;

5 件のコメント

Ricardo Duarte
Ricardo Duarte 2022 年 2 月 1 日
Thank you, it solves the problem partially...
When I maximize the window the alignment/or the scale do not follow that maximization.
What should I do now??
Simon Chan
Simon Chan 2022 年 2 月 1 日
In the lower part of your code, try to add the axis name to those lines using contourf (4 lines) and text (2 lines).
Ricardo Duarte
Ricardo Duarte 2022 年 2 月 1 日
Still not working!
I think that the problem is the following line: set(gcf,'WindowState','maximized'); that maximize the window. It only maximize the ax1 and not the rest...
Thank you.
Ricardo Duarte
Ricardo Duarte 2022 年 2 月 1 日
solved!
somehow when I do "set(gcf,'WindowState','maximized')" matlab kind of need time to adapt plot to the maximized window. I add a "pause(1)" and then I can get the job done.
Thank you!
Voss
Voss 2022 年 2 月 1 日
@Ricardo Duarte: See if using drawnow() in place of pause(1) still works. If it does, then you don't have to wait that extra second.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

質問済み:

2022 年 1 月 31 日

コメント済み:

2022 年 2 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by