Multiple subplots (12) - 6 each align

Hello, I created a figure containing 12 subplots of which 6 each align equally. So I got two "groups" of plots which align equally (group A: 1, 2, 5, 6, 9, 10 and group B: 3,4,7,8,11,12). When using 'position', I had similiar difficulties: the same 6 plots (group A) aligned using a normal vector, the others (group B) used another vector (inches?). What can I do? Plz see the sketch for illustration YES, there are no plots at positions 8 and 12; as stated above and can't be seen on the sketch as I exchanged the plots with white boxes (having a different size) for confidentiality reasons: within the groups A and B the plots align equally;
Any help is appreciated - thank you!

7 Commenti

Share your code.
Hello,
thank you for your reply!
The whole script has ~2000 rows...
..here is an excerpt of the plotting section:
I create the figure and its size using:
hfig=figure;
hfig.Position(3:4)=[1200,600];
pos = get(hfig,'position')
set(hfig,'position',pos.*[.5 1 2 1])
Afterwards, all of the plots are plotted using a code like the following:
if outputSubplots=='Y'
%ax23=subplot('Position',[0.6,0.55,0.175,0.33]);
ax23=subplot(3,4,7)
else
figure;
end
plot(timeincr,T1,'-','Linewidth',2);
hold on;
plot(timeincr,T2,'-.','Linewidth',2)
grid on;
set(gca,'XMinorGrid','on','YMinorGrid','on''XMinorTick','on','YMinorTick','on');
title('Case1')
xlabel(sprintf('Time $\\tau$ in $%s$',texttime),'Interpreter','latex');
ylabel('Temperatures $t_A$ in $^{\circ}C$','Interpreter','latex');
yyaxis right
set(gca,'ycolor','k')
plot(timeincr,T3,':','Linewidth',2)
plot(timeincr,T4,'--','Linewidth',2)
ylabel('Temperatures $t_B$ in $^{\circ}C$','Interpreter','latex');
legend({'$t_{A,1}$','$t_{A,2}$','$t_{B,1}$','$t_{B,2}$'},'Interpreter','latex','Location','best');
if outputSubplots=='N'
if Type>=0.5
suptitle('Type 1')
elseif Type<=0.5
suptitle('Type2')
end
if saveFigures=='Y'
savefig([pathSaveFilePlots, sprintf('%s.fig',filename)]);
sprintf('%s.fig saved in %s',filename,pathSaveFilePlots)
figurepath=[pathSaveFilePlots sprintf('%s.emf',filename)];
saveas(gcf,figurepath);
sprintf('%s.emf saved in %s',filename,pathSaveFilePlots)
end
end
Cris LaPierre
Cris LaPierre il 15 Ott 2021
Modificato: Cris LaPierre il 15 Ott 2021
Is the issue in the figure or the saved image?
Try the followig code. Do you still see the issue when running this on your computer?
texttime = "seconds";
hfig=figure('Visible','on');
hfig.Position(3:4)=[1200,600];
pos = get(hfig,'position')
set(hfig,'position',pos.*[.5 1 2 1])
for p = 1:12
ax = subplot(3,4,p);
timeincr = 1:10;
T1 = rand(size(timeincr));
T2 = rand(size(timeincr));
T3 = rand(size(timeincr));
T4 = rand(size(timeincr));
plot(timeincr,T1,'-','Linewidth',2);
hold on;
plot(timeincr,T2,'-.','Linewidth',2)
grid on;
set(ax,'XMinorGrid','on','YMinorGrid','on','XMinorTick','on','YMinorTick','on');
title('Case1')
xlabel(sprintf('Time $\\tau$ in $%s$',texttime),'Interpreter','latex');
ylabel('Temperatures $t_A$ in $^{\circ}C$','Interpreter','latex');
yyaxis right
set(gca,'ycolor','k')
plot(timeincr,T3,':','Linewidth',2)
plot(timeincr,T4,'--','Linewidth',2)
ylabel('Temperatures $t_B$ in $^{\circ}C$','Interpreter','latex');
legend({'$t_{A,1}$','$t_{A,2}$','$t_{B,1}$','$t_{B,2}$'},'Interpreter','latex','Location','best');
end
filename = ['img_' num2str(p)];
pathSaveFilePlots = './';
savefig([pathSaveFilePlots, sprintf('%s_SHX',filename)]);
sprintf('%s.fig saved in %s',filename,pathSaveFilePlots)
figurepath=[pathSaveFilePlots sprintf('%s.emf',filename)];
saveas(gcf,figurepath);
sprintf('%s.emf saved in %s',filename,pathSaveFilePlots)
Michael Wernhart
Michael Wernhart il 15 Ott 2021
Modificato: Michael Wernhart il 15 Ott 2021
...in the figure.
btw: not all y axes have the same length.
Is there a limitation on the amount of subplots? / is there a "critical" amount of subplots in one figure? (The graphs plotted have up to 40,000 entries each and there are up to 5 graphs in one figure)
..what I recognized also is, that one subplot (Position 4 on sketch in the first post) has a frame on the left y-axis only but none on the right (it has no graph on the right y-axis). Other subplots have no graph on the right y-axis but do have a frame on the right y-axis.
this worked well - i also set timeincr to 1:40000 and it worked well too; no errors in the appearance of the plots..
That suggests to me there might be something with your data. Try creating the figures one at a time and see if you can identify if one of them is not being created properly (perhaps #4?). Inspect the corresponding data for clues as to what may be happening.

Accedi per commentare.

 Risposta accettata

Michael Wernhart
Michael Wernhart il 15 Ott 2021
Modificato: Michael Wernhart il 15 Ott 2021

0 voti

More than that, I saw that I set the axes several times to "normal" - though the code was very similiar (mostly the same but at other positions) and except "axes normal" never changed the position given by subplot(m,n,p) that might caused some error?
working through the code again and standardizing it helped (+ i moved the calculation of the plots with the most data on top)!
Thank you very much!
Kind regards!

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by