- Create axes in tiled positions - https://www.mathworks.com/help/matlab/ref/subplot.html
- Create annotations - https://www.mathworks.com/help/matlab/ref/annotation.html
Title for a column of subplots
18 views (last 30 days)
Show older comments
I want to have a title for each column and row of subplots. I've tried using sgtitle but it is not giving me the effect I want. Is there another way to achieve this? I've included a simplifed example below of what I want to achieve.
0 Comments
Answers (1)
ag
on 26 Sep 2024
Hi Eileen,
To achieve titles for each column and row of subplots, you can manually add text annotations to the figure. This allows you to place titles exactly where you want them.
The below code demonstrates how to achieve this using dummy data:
% Create a figure
figure;
% Create a 2x2 grid of subplots for demonstration
subplot(2, 2, 1);
plot(rand(10, 1));
title('Plot 1');
subplot(2, 2, 2);
plot(rand(10, 1));
title('Plot 2');
subplot(2, 2, 3);
plot(rand(10, 1));
title('Plot 3');
subplot(2, 2, 4);
plot(rand(10, 1));
title('Plot 4');
% Add row titles
annotation('textbox', [0.01, 0.75, 0.1, 0.1], 'String', 'Row 1', 'EdgeColor', 'none', 'FontSize', 12, 'FontWeight', 'bold');
annotation('textbox', [0.01, 0.25, 0.1, 0.1], 'String', 'Row 2', 'EdgeColor', 'none', 'FontSize', 12, 'FontWeight', 'bold');
% Add column titles
annotation('textbox', [0.3, 0.95, 0.1, 0.1], 'String', 'Column 1', 'EdgeColor', 'none', 'FontSize', 12, 'FontWeight', 'bold');
annotation('textbox', [0.7, 0.95, 0.1, 0.1], 'String', 'Column 2', 'EdgeColor', 'none', 'FontSize', 12, 'FontWeight', 'bold');
For more details, please refer to the following MathWorks documentations:
Hope this helps!
0 Comments
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!