- 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
39 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/385943/image.png)
0 comentarios
Respuestas (1)
ag
el 26 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Labels and Annotations 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!