Misalignment plot with several axes

2 次查看(过去 30 天)
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
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
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 个)

类别

Help CenterFile Exchange 中查找有关 Data Exploration 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by