How can I label my graphs as (a), (b), (c) etc in subplot matlab?
369 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shikhar Saxena
el 13 de Dic. de 2018
Comentada: Matt J
el 18 de Mayo de 2023
I want to describe the graphs in figure caption by referencing them as (a), (b) (c) etc
1 comentario
Respuesta aceptada
Image Analyst
el 13 de Dic. de 2018
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198961/0000%20Screenshot.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.
Más respuestas (4)
Sterling Baird
el 21 de Oct. de 2020
Editada: Sterling Baird
el 21 de Oct. de 2020
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/386913/image.png)
4 comentarios
Image Analyst
el 13 de Abr. de 2022
@Wiqas Ahmad Try using text() or put it into the title or axes labels using sprintf() and title() or xlabel() or ylabel().
Sanita Dhaubanjar
el 2 de Mayo de 2023
You can make the label generation shorter using:
charlbl = compose("(%s)",('a':'z').');
madhan ravi
el 13 de Dic. de 2018
Editada: madhan ravi
el 13 de Dic. de 2018
Use legend()
legend('(a)','(b)','(c)')
Alex Ryabov
el 7 de Jul. de 2021
Editada: Alex Ryabov
el 7 de Jul. de 2021
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')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/676833/image.png)
0 comentarios
Dion Wilde
el 17 de Mayo de 2023
Editada: Dion Wilde
el 18 de Mayo de 2023
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 comentarios
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!