필터 지우기
필터 지우기

Label rows and columns of subplots

조회 수: 18 (최근 30일)
Hellen Jing Yuan
Hellen Jing Yuan 2018년 12월 7일
댓글: Hellen Jing Yuan 2018년 12월 10일
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
Koundinya
Koundinya 2018년 12월 10일
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 2018년 12월 10일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by