How do I use suptitle in my subplot
311 ビュー (過去 30 日間)
古いコメントを表示
Hi guys
I'm doing I subplot, where I want to make one "Super title". When I use the function suptitle the subplots gets weird! I have attached both plots with and without suptitle function, so you can see the difference...
for j=1:length(SR)
figure
for i=[1:4 6:9] %Creating row x collums for subplot
for c=1:8 %Number of headings
subplot(3,3,i)
plot(omega,Sp_we(:,c,j))
end
suptitle ('Wave spectrum for')
end
end
Isa Duran
1 件のコメント
dpb
2014 年 5 月 23 日
編集済み: dpb
2014 年 5 月 23 日
Don't have it; it's in a toolbox don't have so can't do anything except offer advice.
My first attempt at workaround would be to save the position vectors of all the subplots before calling suptitle and then reset them after it and see if that works ok. Variations on a theme afterwards may yet be needed.
There's a submission on File Exchange that has the functionality with 4 or 5 stars you might look at as well...I forget the exact submission name but a search for "suptitle" did find it.
Ok, the link was still in my browser recall...
採用された回答
Cedric
2014 年 5 月 23 日
編集済み: Cedric
2014 年 5 月 24 日
I usually build the array of subplots by myself in these cases, because I find that SUBPLOT is a bit too rigid. This essentially means placing axes within a figure, on a grid of equally spaced coordinates of axes lower left corners ((0,0) being the coordinates of the lower left corner if the figure and (1,1) the upper right corner). Here is an example.
% - Define dummy data: 11 time series.
t = 0 : 0.1 : 10 ;
data = 2 * repmat( sin(t).', 1,11 ) + rand( length(t), 11 ) ;
nSeries = size( data, 2 ) ;
% - Build figure.
figure() ; clf ;
set( gcf, 'Color', 'White', 'Unit', 'Normalized', ...
'Position', [0.1,0.1,0.6,0.6] ) ;
% - Compute #rows/cols, dimensions, and positions of lower-left corners.
nCol = 4 ; nRow = ceil( nSeries / nCol ) ;
rowH = 0.58 / nRow ; colW = 0.7 / nCol ;
colX = 0.06 + linspace( 0, 0.96, nCol+1 ) ; colX = colX(1:end-1) ;
rowY = 0.1 + linspace( 0.9, 0, nRow+1 ) ; rowY = rowY(2:end) ;
% - Build subplots axes and plot data.
for dId = 1 : nSeries
rowId = ceil( dId / nCol ) ;
colId = dId - (rowId - 1) * nCol ;
axes( 'Position', [colX(colId), rowY(rowId), colW, rowH] ) ;
plot( t, data(:,dId), 'b' ) ;
grid on ;
xlabel( '\theta(t) [rad]' ) ; ylabel( 'Anomaly [m]' ) ;
title( sprintf( 'Time series %d', dId )) ;
end
% - Build title axes and title.
axes( 'Position', [0, 0.95, 1, 0.05] ) ;
set( gca, 'Color', 'None', 'XColor', 'White', 'YColor', 'White' ) ;
text( 0.5, 0, 'My Nice Title', 'FontSize', 14', 'FontWeight', 'Bold', ...
'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom' ) ;
EDIT: this outputs

0 件のコメント
その他の回答 (1 件)
Michelle Hirsch
2020 年 3 月 5 日
This capability is now built into core MATLAB. sgtitle ("Add title to subplot grid") was introduced in 18b. We also introduced tiledlayout in 19b as an alternative to subplot that gives more control over axes spacing, automatic layout reflowing as you add more axes, and support for titles, xlabels, ylabels that span multiple axes.
5 件のコメント
Michelle Hirsch
2025 年 3 月 3 日 12:36
I'm not aware of ways to move an sgtitle. It doesn't have a position property.
There are plenty of copies of suptitle floating around on the File Exchange, in submissions that redistribute it. suptitle used to be on File Exchange. It shipped with a toolbox in support of a demo, but it was never meant to be a documented, supported functions. You are welcome to grab it from one of them.
dpb
2025 年 3 月 3 日 17:29
編集済み: dpb
2025 年 3 月 3 日 20:14
"I'm not aware of ways to move an sgtitle. It doesn't have a position property."
Another of these things where Mathworks seems to think "Mother knows best!" and hides what almost certainly there will cases in which users have need or desire to customize the packaged results.
But, one can get there; it just takes digging...of course, anything that isn't exposed is subject to the possibility of breaking in the future and things like printing or zoom may not work as expected.
Locally on R2021b, the following is possible
>> hSG=sgtitle('My SGTITLE String');
>> hSG.NodeChildren.Children
ans =
2×1 graphics array:
ListOfPointsHighlight
Text (SGTitle)
>> hSG_Text=hSG.NodeChildren.Children(2)
hSG_Text =
Text (My SGTITLE String) with properties:
String: 'My SGTITLE String'
FontSize: 13.00
FontWeight: 'normal'
FontName: 'Helvetica'
Color: [0 0 0]
HorizontalAlignment: 'center'
Position: [0 0.86 0]
Units: 'data'
Show all properties
>>
Of course, it takes spelunking with <Yair Altman's submission> to uncover the undocumented/hidden properties, but it's almost imperative when customization needs exceed that Mathworks has provided. This is particularly so with all the new-fangled customized presentation objects that are maddening in their penchant to be almost or totally opaque.
参考
カテゴリ
Help Center および File Exchange で Graphics Object Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!