- Refer to the documentation of subplot for creating subplot grids: https://www.mathworks.com/help/matlab/ref/subplot.html
- Refer to the documentation of sgtitle for adding a title to a subplot grid: https://www.mathworks.com/help/matlab/ref/sgtitle.html
- Refer to the documentation of text for adding text annotations: https://www.mathworks.com/help/matlab/ref/text.html
Add title to one row of a subplot
55 ビュー (過去 30 日間)
古いコメントを表示
I am using subplot and there 6*2. I want to add title for every two plots that are in the same row.
Any suggestion?
0 件のコメント
回答 (2 件)
Hari
2024 年 9 月 3 日
Hi Zeynab,
I understand that you want to add a single title to each row of a subplot grid that has 6 rows and 2 columns in MATLAB. Each title should span the two subplots in the same row.
I assume you are using the subplot function to create your grid
You can use the "sgtitle" function to add a title that spans the entire figure. For individual row titles, you can use the "text" function to place a title above each pair of subplots.
Here is the sample code for the same:
% Example: Create a 6x2 subplot grid
for i = 1:12
subplot(6, 2, i);
plot(rand(1, 10)); % Example plot
end
% Add a main title for the whole figure
sgtitle('Main Title for the Subplot Grid');
% Add titles for each row
for i = 1:6
% Calculate position for the text
text(0.5, 0.5, sprintf('Row %d Title', i), 'Units', 'normalized', ...
'HorizontalAlignment', 'center', 'FontSize', 10, ...
'Position', [0.5, 1.1, 0], 'Parent', subplot(6, 2, (i-1)*2+1));
end
Output:
References:
Hope this helps!
0 件のコメント
Adam Danz
2024 年 9 月 5 日
Instead of using subplot, I recommend using tiledlayout which supports nested layouts and global titles.
Follow these instructions to create a centered title for each row in a tiled layout or in when using subplot.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!