How to create several figures in a subplot with different axes?

Illustration
RicardoDuarte - 2024-06-29T20:29:58+00:00
Question: How to create several figures in a subplot with different axes?

Dear all, I'm trying to create a subplot with 7lines and 1 column that plot all of my results consecutivelly. I have this piece of code: subplot(7,1,k); ax1=axes; imagesc(ax1,Xv,Yv,M); set(gca,'YDir','normal'); h=colorbar; ylabel(h,'TOTAL Sound Pressure Level (dB)'); clear title title(strcat('SPL Broadband\_', listofpercentis(k))); xlabel('LONGITUDE'); ylabel('LATITUDE'); axis tight; clear title ax2=axes; contourf(ax2,lon_km,lat_km,elevation', [0 0]); linkaxes([ax1,ax2]); ax2.Visible = 'off'; ax2.XTick = []; ax2.YTick = []; set([ax1,ax2],'Position',[.17 .11 .685 .815]); ax2.Visible = 'on'; ax2.Visible = 'off'; cb1 = colorbar(ax1,'Position',[.865 .112 .04 .815]); ylabel(cb1, 'SPL (dB)','FontSize',12); %AUTOMATIC WAY % xlim([ax1,ax2],[xmin xmax]); % ylim([ax1,ax2],[ymin ymax]); axes(ax1); axis equal; axes(ax2); axis equal; hold on; %plot(km2deg(Sx),km2deg(Sy), '*k') %plot(-9,37.96, 'Ok'); %source=text(deg2km(-8.99),deg2km(37.94),'source','FontSize',12) portugal=text(deg2km(-8.65),deg2km(37.86),'Portugal','FontSize',20); set(portugal,'Rotation',90); sines=text(deg2km(-8.869),deg2km(37.96),'*Sines','FontSize',14); caxis(ax1,[0 200]); The problem is that all plots are displayed in the same position and I want to display the first plot in the first line, the second plot in the second line, etc etc.

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

You're aren't using subplot correctly. For each plot you need a separate call to subplot with the index (in your case, row) where you want the plot to appear:

subplot(7,1,1); plot ... % something in the 1st row subplot(7,1,2); plot ... % something in the 2nd row subplot(7,1,3); plot ... % something in the 3rd row ...

Type doc subplot in the MATLAB's command window for more explanation and examples


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!