How can I label my graphs as (a), (b), (c) etc in subplot matlab?

조회 수: 576 (최근 30일)
Shikhar Saxena
Shikhar Saxena 2018년 12월 13일
댓글: Matt J 2023년 5월 18일
I want to describe the graphs in figure caption by referencing them as (a), (b) (c) etc

채택된 답변

Image Analyst
Image Analyst 2018년 12월 13일
Use subplot() and title().
% Plot (a) plot.
subplot(3, 1, 1);
plot(1:10, 'r-');
title('(a)', 'FontSize', 15);
% Plot (b) plot.
subplot(3, 1, 2);
plot(10*sin(0:.1:10), 'b-', 'LineWidth', 2);
grid on;
title('(b)', 'FontSize', 15);
% Plot (a) plot.
subplot(3, 1, 3);
plot(cos(1:10), 'k*', 'MarkerSize', 15, 'LineWidth', 2);
grid on;
title('(c)', 'FontSize', 15);
0000 Screenshot.png
Or you could use xlabel() if you want to put the letters under the x axis, or text() if you want to place them wherever you want.
  댓글 수: 7
Steven Lord
Steven Lord 2020년 9월 23일
One possibility is to use the text function.
Sterling Baird
Sterling Baird 2020년 10월 19일
I think Image Analyst's solution may need a bit more to get left alignment.

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

추가 답변 (4개)

Sterling Baird
Sterling Baird 2020년 10월 21일
편집: Sterling Baird 2020년 10월 21일
Personally, I've liked using:
nIDs = 4;
alphabet = ('a':'z').';
chars = num2cell(alphabet(1:nIDs));
chars = chars.';
charlbl = strcat('(',chars,')'); % {'(a)','(b)','(c)','(d)'}
text(0.025,0.95,charlbl{1},'Units','normalized','FontSize',12)
This works fine for me for tiled layouts, and does a decent job for scientific figures.
  댓글 수: 4
Image Analyst
Image Analyst 2022년 4월 13일
@Wiqas Ahmad Try using text() or put it into the title or axes labels using sprintf() and title() or xlabel() or ylabel().
Sanita Dhaubanjar
Sanita Dhaubanjar 2023년 5월 2일
You can make the label generation shorter using:
charlbl = compose("(%s)",('a':'z').');

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


madhan ravi
madhan ravi 2018년 12월 13일
편집: madhan ravi 2018년 12월 13일
Use legend()
legend('(a)','(b)','(c)')
  댓글 수: 1
Shikhar Saxena
Shikhar Saxena 2018년 12월 13일
No, legend is different. I want to label each graph as a,b,c etc. Like see in figure below generated through subplot function matlab, I want to label three graphs as a, b and c. try.png

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


Alex Ryabov
Alex Ryabov 2021년 7월 7일
편집: Alex Ryabov 2021년 7월 7일
I hope this function will help
fg = figure(1);
clf
subplot(2, 2, 1)
subplot(2, 2, 2)
subplot(2, 1, 2)
legend
colorbar
AddLetters2Plots(fg, 'HShift', 0, 'VShift', 0, 'Direction', 'TopDown')

Dion Wilde
Dion Wilde 2023년 5월 17일
편집: Dion Wilde 2023년 5월 18일
Personally i found my optimum with the following solution:
ax=gca;
% read out the position of the axis in the unit "characters"
set(ax,'Units','characters'); a=get(ax,'Position');
% this determines the type of the plot
if isequal(get(ax,'View'),[0 90]) % this is used for 2D plots
str_place=2;
else % this is used for 3D plots, in this case also all other plots
str_place=-2;
end
% this sets an 'a)' right at the top left of the axes
text(ax,0,a(end)+str_place,'a)','Units','characters')
I specifically used the units "characters" here, because it consistently sets the character above the axes indepently of the actual size of the axis. The latter is difficult if not impossible to do with "units", "normalized".
  댓글 수: 2
Sreeraj T
Sreeraj T 2023년 5월 18일
What does "end" in the last line indicates? It ends what?
Dion Wilde
Dion Wilde 2023년 5월 18일
my bad, i copy pasted it from my own code. I deleted the "end".

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

카테고리

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

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by