Borrar filtros
Borrar filtros

Label rows and columns of subplots

18 visualizaciones (últimos 30 días)
Hellen Jing Yuan
Hellen Jing Yuan el 7 de Dic. de 2018
Comentada: Hellen Jing Yuan el 10 de Dic. de 2018
I have six figures (in .fig format) and would like to arrange them in a 2x3 subplot and then label each row and column of subplots. In specific, I want to label the two rows 'Participant 1' and 'Participant 2', and the three columns 'Frequency set 1', 'Frequency set 2' and 'Frequency set 3'.
Below is the code I tried:
% give the path of .fig to be plotted together
figName1 = '/.../participant1/freqSet1.fig';
figName2 = '/.../participant1/freqSet2.fig';
figName3 = '/.../participant1/freqSet3.fig';
figName4 = '/.../participant2/freqSet1.fig';
figName5 = '/.../participant2/freqSet2.fig';
figName6 = '/.../participant2/freqSet3.fig';
% list all variables starting w/ 'figName'
figList = who('figName*');
% Load saved figures
fig1=hgload(figName1);
fig2=hgload(figName2);
fig3=hgload(figName3);
fig4=hgload(figName4);
fig5=hgload(figName5);
fig6=hgload(figName6);
% Prepare subplots
figure
for iSubPlot = 1:length(figList)
h(iSubPlot) = subplot(2,3,iSubPlot);
if iSubPlot==1
text(-0.35, 0.5,'Participant 1');
text(0.35,1.1,'Frequency set 1');
elseif iSubPlot==2
text(0.35,1.1,'Frequency set 2');
elseif iSubPlot==3
text(0.35,1.1,'Frequency set 3');
elseif iSubPlot==4
text(-0.35, 0.5,'Participant 2');
end
end
% now the desired labels have been applied
% Paste figures on the subplots
copyobj(allchild(get(fig1,'CurrentAxes')),h(1));
copyobj(allchild(get(fig2,'CurrentAxes')),h(2));
copyobj(allchild(get(fig3,'CurrentAxes')),h(3));
copyobj(allchild(get(fig4,'CurrentAxes')),h(4));
copyobj(allchild(get(fig5,'CurrentAxes')),h(5));
copyobj(allchild(get(fig6,'CurrentAxes')),h(6));
% now the subplots are pasted, the previous row and column labels are gone
As described in the code comments, the row and column lables disappear after I paste the figures into the subplot. Do you know how I can fix this? Thanks very much!
  5 comentarios
Koundinya
Koundinya el 10 de Dic. de 2018
Tried this in R2015a and R2017a, the labels are intact. In your case ,maybe the labels are not visible because they are being obstructed by the figures ?
Hellen Jing Yuan
Hellen Jing Yuan el 10 de Dic. de 2018
The figures fit within the space of each subplot, so it shouldn't obstruct the labels...
I suspect that this line
copyobj(allchild(get(fig1,'CurrentAxes')),h(1));
overrides the previous setting of the lables. But even when I do something like this
copyobj(allchild(get(fig1,'CurrentAxes')),h(1));
text(-0.35, 0.5,'Participant 1');
text(0.35,1.1,'Frequency set 1');
copyobj(allchild(get(fig2,'CurrentAxes')),h(2));
text(0.35,1.1,'Frequency set 2');
The labels are still missing.

Iniciar sesión para comentar.

Respuestas (0)

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by