How do I change position of titles and subtitles of subplots? (2024)

237 views (last 30 days)

Show older comments

Samuele Bolotta on 15 Feb 2021

  • Link

    Direct link to this question

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots

  • Link

    Direct link to this question

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots

Commented: Adam Danz on 7 Aug 2024 at 12:23

Accepted Answer: Adam Danz

  • Screenshot from 2021-02-15 14-13-10.png

Open in MATLAB Online

I attached a screenshot of my plot.

I would like to put on the left (instead of above) the titles (Currents at -70mv, -50, -30 and -10) of the four subplots on the left; on the other hand, I would like to put on the right (instead of above) the titles (Currents at -60mv, -40, -20 and 0) of the four subplots on the right. This is to save space and delete some of the blank space between the subplots.

As for the subtitle ("I is 2 times slower than E"), I'd like to have only one instead of eight, possibly above all the subplots in the centre.

This is how I'm doing now (there's another for loop "for rat = 1:colnum2" outside here but it's not relevant for this question):

for vol = 1:colnum

subplot(4,2,vol);

plot(t_plot, currents(:,hh:zz), 'linewidth',2); legend('IPSC', 'EPSC', 'CPSC');

str = sprintf('Currents at %d mV ', Vm(1,vol));

title(str)

subtitle(['I is ', num2str(ratio(rat)), ' times slower than E'])

xlabel('Time(msec)', 'fontsize', 7)

ylabel('Microamperes (uA)', 'fontsize', 7);

hh = hh + niter;

zz = zz + niter;

end

Thanks!

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Adam Danz on 15 Feb 2021

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#answer_624052

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#answer_624052

Starting in r2020b you can set the TitleHorizontalAlignment property of the axes to specify the justification (left|right|center).

There are similar properties for the xlabel and ylabel, too. See this Community Hightlight for a review.

https://www.mathworks.com/matlabcentral/discussions/highlights/133180

How do I change position of titles and subtitles of subplots? (3)

10 Comments

Show 8 older commentsHide 8 older comments

dpb on 15 Feb 2021

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330497

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330497

Kewl. I'm on R2019b.

Didn't fix unalterable position for the SGTITLE() by any chance, did they?

dpb on 15 Feb 2021

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330587

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330587

Open in MATLAB Online

With this, above could be

...

for i=1:8

hAx(i)=subplot(4,2,i);

hT(i)=title(str{i});

hAx(i).TitleHorizontalAlignment=hposn{mod(i+1,2)+1};

end

...

perhaps a little cleaner.

Adam Danz on 15 Feb 2021

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330642

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330642

Open in MATLAB Online

It looks like sgtitle positions are still not editable.

Another alternative:

for i=1:8

hAx(i)=subplot(4,2,i);

title(str{i});

end

set(hAx(1:2:end),'TitleHorizontalAlignment', 'Left')

set(hAx(2:2:end),'TitleHorizontalAlignment', 'Right')

dpb on 15 Feb 2021

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330767

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_1330767

Edited: dpb on 15 Feb 2021

Yeah, good idea to fix up after the fact; requires set since dot notation won't accept arrays.

You can move sgtitle() around on the figure with the hidden properties so the on-screen version looks as modified; "SaveAs" causes the position to be overwritten, though. I didn't pursue any further to see if could manage to stop that with futzing with callbacks, etc., ...

evelyn on 6 Aug 2024 at 1:34

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3230691

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3230691

how to change 'sgtitle' from top to bottom?

Walter Roberson on 6 Aug 2024 at 2:42

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3230731

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3230731

@evelyn

sgtitle() returns a Text object. You can adjust the position of the Text object. It might take some playing with the coordinates, unless you set the Units property to 'normalized' and then use normalized coordinates.

evelyn on 6 Aug 2024 at 6:24

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3230866

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3230866

Open in MATLAB Online

thank you for your reply. How to change the position?

sgt = sgtitle('(a)')

How do I change position of titles and subtitles of subplots? (11)

sgt =

Text ((a)) with properties: String: '(a)' FontSize: 13 FontWeight: 'normal' FontName: 'Helvetica' Color: [0 0 0] Interpreter: 'tex' Use GET to show all properties

sgt.Position

Unrecognized method, property, or field 'Position' for class 'matlab.graphics.illustration.subplot.Text'.

Adam Danz on 6 Aug 2024 at 14:43

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3231216

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3231216

Open in MATLAB Online

@evelyn I suggest you use tiledlayout which supports global titles and labels.

You can use xlabel to assign a title to the bottom of the figure.

tcl = tiledlayout(2,2);

nexttile

title('a')

nexttile

title('b')

nexttile

title('c')

nexttile

title('d')

t = title(tcl,'Global title','FontSize', 20);

xlabel(tcl,'Global title on botton','FontSize', 20)

How do I change position of titles and subtitles of subplots? (13)

evelyn on 7 Aug 2024 at 5:12

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3231724

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3231724

thank you for your reply! I think that is what I need.

Is there any way to add title to the bottem of each subplot?

Adam Danz on 7 Aug 2024 at 12:23

Direct link to this comment

https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3232014

  • Link

    Direct link to this comment

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#comment_3232014

You could use the xlabel function or text() but if the axes limits update, the relative text position may change.

Sign in to comment.

More Answers (1)

dpb on 15 Feb 2021

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#answer_624042

  • Link

    Direct link to this answer

    https://physical-modeling.mathworks.com/matlabcentral/answers/745962-how-do-i-change-position-of-titles-and-subtitles-of-subplots#answer_624042

Open in MATLAB Online

Try

str=compose('Currents at %d mV ', [-70:10:0]);

hposn={'left','right'};

figure

for i=1:8

hAx(i)=subplot(4,2,i);

hT(i)=title(str{i},'Position',[mod(i+1,2) 1.03],'horizontalAlignment',hposn{mod(i+1,2)+1});

end

hSG=sgtitle('I is 2 times slower than E','fontsize',9);

hNC=hSG.NodeChildren.Children(2);

hNC.Position(2)=0.825;

Again, TMW got too clever for their own good; the 'Position' property of the text object that is the subplot grid title is hidden as is the text object itself buried deep inside the returned composite handle object. Consequently, moving it around a little is a pain.

On a default figure here, the y-position turns out to be 0.88; that appears to high for the effect I think you are looking for; the 0.825 is an empirical adjustment; also while the text is centered over the entire figure horizontally, it also appears somewhat off center owing to the placement of the axes inside the area; you can fiddle with positions of each of the subplots to close them up as desired and then adjust as needs be.

The above for just default produced:

How do I change position of titles and subtitles of subplots? (17)

ADDENDUM: Just realized that when saving the figure, the SGTITLE() text position gets overwritten back to default. That appears to be unavoidable; you might end up having to just use TEXT() directly instead, altho the locations of the titles are easy enough to handle.

You might want to investigate the tiledlayout instead, it may give you more nearly the spacings between plots you're looking for without as much mucking around as subplot requires. I've not messed with it much so can't say for sure...

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphicsFormatting and AnnotationLabels and AnnotationsAxis Labels

Find more on Axis Labels in Help Center and File Exchange

Tags

  • plot
  • subplot
  • plotting
  • matlab
  • title
  • subtitle

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


How do I change position of titles and subtitles of subplots? (18)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

How do I change position of titles and subtitles of subplots? (2024)

References

Top Articles
Extramedullary Hematopoiesis in Breast after Neoadjuvant Chemotherapy for Breast Carcinoma
Comparison of predictive models in postoperative nausea and vomiting in patients undergoing breast cancer surgery
Tripadvisor Antigua Forum
A Man Called Otto Showtimes Near Fort Collins
Culver's Flavor Of The Day Ann Arbor
Booked On The Bayou Houma 2023
Busted Newspaper Birmingham Al
The KT extinction
South Park Season 26 Kisscartoon
Saratoga Hills Single-Family Homes for Sale
Dr Paul Memorial Medical Center
Msu Ro
Dd Codeshare
J/99 – der neue Hochseerenner
The Nun 2 Showtimes Tinseltown
Wausau Pilot Obituaries
Osrs Mahogany Homes Calc
Berkeley Law Bookstore
Lufkin Isd Calendar
Xiom Vega X Review & Playtesting • Racket Insight
Jordan Torres Leaked
Rachel Zoe first outing hours after announcing shock marriage split
Crowder Hite Crews Funeral Home Obituaries
Unmhealth My Mysecurebill
Cognitive Function Test Potomac Falls
Management Trainee: Associate Adjuster - June 2025
Belly Button Torture Video
The Lives of Others - This American Life
Southeast Ia Craigslist
Game8 Genshin Impact
Marissa.munoz17
What Happened To Doublelist? Unveiling The Mystery | Men's Venture
Ups Near Me Open
Chipotle Digital Kitchen Briggs Chaney
Crazy 8S Cool Math
Candy Land Santa Ana
Witchwood Icon
Grupos De Cp Telegram
Ticket To Paradise Showtimes Near Laemmle Newhall
Papa Louie When Pizzas Attack Unblocked
Little League Coach Daily Themed Crossword
Puppies For Sale in Netherlands (98) | Petzlover
Sprague Brook Park Camping Reservations
Ece 2300 Osu
Bryant Air Conditioner Parts Diagram
Appsanywhere Mst
Sloansmoans Many
Directions To 401 East Chestnut Street Louisville Kentucky
Hershey Company Myhr
What Time Does The Chase Bank Close On Saturday
Rs3 Spectral Spirit Shield
The Ultimate Guide to Newquay Surf - Surf Atlas
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5857

Rating: 4.6 / 5 (76 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.