How do I use suptitle in my subplot
Mostra commenti meno recenti
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 Commento
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...
Risposta accettata
Più risposte (1)
Michelle Hirsch
il 5 Mar 2020
10 voti
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 Commenti
Diaa
il 1 Mag 2021
In tiledlayout, there no such an option to control the exact spacing between the subplots. Is there a way to do so at the moment?
Michelle Hirsch
il 3 Mag 2021
@Diaa, I'm not aware of a way to do that, since tiledlayout is designed to behave like a layout manager - you give it guidance on how to behave, and it takes care of the details. Could you say more about why you'd like to control the exact spacing? This will help us figure out if we should enhance tiledlayout to support this.
Edwin Moon
il 28 Feb 2025
Hello, is there a way of moving the position of the sgtitle so it does overlay on top of the subplot title? In fact, when I try moving sgtitle using the arrow tool in the figure window, I can't move it anywhere on the figure - it's stuck in the position where the code left it. The subplot titles, axes titles, and graphs are movable.
Surely the sgtitle can be moved to a more sensible location?
Previously, in 2013a, I was able to use 'suptitle (xxx)' followed by 'set(gco,'position',[0 1 1 1])' which seemed to work OK. It would be really good to have suptitle available for use in 2023b so I can keep my original code - if this is an option, please let me know.
Any help would be very much appreciated.
Many thanks
Edwin
Michelle Hirsch
il 3 Mar 2025
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.
"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.
Categorie
Scopri di più su 2-D and 3-D Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
