Title for a column of subplots

17 Ansichten (letzte 30 Tage)
Eileen Lukens
Eileen Lukens am 19 Okt. 2020
Beantwortet: ag am 26 Sep. 2024
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.

Antworten (1)

ag
ag am 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!

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by