AddLetters2Plots

version 1.1.3 (3.15 KB) by Alex Ryabov
Matlab function to add labels a, b, c to subplots in a figure.

321 Downloads

Updated 25 Aug 2022

View License

AddLetters2Plots - adds labels A, B, ... to subplots in a figure.
This function adds lables to the axes. You can change the letters, define the figure or a list of axes on which you want to add letters, change the position of the letters relative to subplots (as well as positioning the letters inside or outside the subplot), and change the font size.
Syntax:
AddLetters2Plots(fg_or_axes,Letters,Name, Value)
Inputs:
fg_or_axes - figure or a cell array of axes, by defeult is the current
figure
Letters - cell array of letters, by default {'A',...'Z'})
AddLetters2Plots(fg_or_axes,Letters,Name1, Value1,Name2, Value2, ...)
specifies one or more of the following name/value pairs:
'FontSize'
'FontWeight' -- 'normal' | 'bold'(default)
'Color' [0 0 0] (default)
'HShift' and 'VShift' - horizontal and vertical shifts
relative shift from -1 to 1 from the upper left cornner of the axis. default = 0 positive values for plotting inside the subplots, negative for plotting outside the subplots. if HShift, VShift are vectors, then different relative shifts are defined for each axis
'Location' location of the labels
'NorthWest'(default) 'NorthEast','SouthEast', 'NorthWest','SouthWest'
'FitLocation' false (default) 'FitLocation' = true
provides a better atomatic placement of letters but is much slower because in this case drawnow function is used
'Direction' = 'LeftRight' or 'TopDown' label figures either from left
to right or from top to down
Example:
Add letters A, B to the current figure
AddLetters2Plots
Add letters A, B to figure fg
AddLetters2Plots(fg)
Add letters (a), (b) and (c) to fg
AddLetters2Plots(fg, {'(a)', '(b)', '(c)'})
Add (a), (b) and (c) to axis1, axis2, axis3
AddLetters2Plots({ax1, ax2, ax3}, {'(a)', '(b)', '(c)'})
Add default letters outside of figures, order figure labeling from from top to bottom
AddLetters2Plots(fg, 'HShift', -0.08, 'VShift', -0.02, 'Direction', 'TopDown')
Code example
fg = figure(1);
clf
subplot(2, 2, 1)
subplot(2, 2, 2)
subplot(2, 1, 2)
legend
colorbar
AddLetters2Plots( 'HShift', [0, 0, 0], 'VShift', 0, 'Direction', 'LeftRight', 'FontSize', 10)
Add latters to some axes only
fg = figure(2);
clf
ax1 = subplot(2, 2, 1);
ax2 = subplot(2, 2, 2);
ax3 = subplot(2, 1, 2);
legend
colorbar
AddLetters2Plots({ax1, ax3}, {'A', 'B'})
Add red letters in the bottom left corner. Note in this case the letters are outside of the axes.
figure(3);
ax1 = subplot(2, 2, 1);
ax2 = subplot(2, 2, 2);
ax3 = subplot(2, 1, 2);
AddLetters2Plots('HShift', [0, 0, 0], 'VShift', 0, 'Color', 'red', ...
'Location', 'SouthEast')
Add red letters in the bottom left corner and automatically move them into the axis boxes. SLOW!!! because of the drawnow function.
figure(4);
ax1 = subplot(2, 2, 1);
ax2 = subplot(2, 2, 2);
ax3 = subplot(2, 1, 2);
AddLetters2Plots('HShift', [0, 0, 0], 'VShift', 0, 'Color', 'red', ...
'Location', 'SouthEast', 'FitLocation', true)

Cite As

Alex Ryabov (2022). AddLetters2Plots (https://www.mathworks.com/matlabcentral/fileexchange/95478-addletters2plots), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021a
Compatible with R2019b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!