Clear Filters
Clear Filters

How to tile m by n plots (all different) and add row titles

53 views (last 30 days)
I have a number of independent plots, with their own axis properties, to tile into rows and columns. I can do this with 'tiledlayout' (recommended over 'subplot'), and using 'nexttile(x)', where 'x' is the position of the plot within the tiled scheme. Because the plots are different, I cannot use a for/end loop, and the values for 'x' are hard-coded. How do I add a title for each of the two rows in that scheme?
%% Simplistic example
v=tiledlayout(2,4);
nexttile(1)
plot(rand(8,1));% own properties
nexttile(2)
plot(rand(8,1));% own properties
nexttile(3)
plot(rand(8,1));% own properties
nexttile(4)
plot(rand(8,1));% own properties
nexttile(5)
plot(rand(8,1));% own properties
nexttile(6)
plot(rand(8,1));% own properties
nexttile(7)
plot(rand(8,1));% own properties
nexttile(8)
plot(rand(8,1));% own properties
title(v,'Master Title')

Accepted Answer

the cyclist
the cyclist on 6 Oct 2023
You can use the annotation command to add text annotations to your figure.
v=tiledlayout(2,4);
nexttile(1)
plot(rand(8,1));% own properties
nexttile(2)
plot(rand(8,1));% own properties
nexttile(3)
plot(rand(8,1));% own properties
nexttile(4)
plot(rand(8,1));% own properties
nexttile(5)
plot(rand(8,1));% own properties
nexttile(6)
plot(rand(8,1));% own properties
nexttile(7)
plot(rand(8,1));% own properties
nexttile(8)
plot(rand(8,1));% own properties
title(v,'Master Title')
annotation("textbox",[0.48 0.45 0.1 0.1],"String","Row 1 title","EdgeColor","none")
annotation("textbox",[0.48 0.00 0.1 0.1],"String","Row 2 title","EdgeColor","none")
It's admittedly a tight squeeze, but the bottom annotation can't go any lower. You could make the fonts smaller to create a bit more space.
  2 Comments
Paul Barrette
Paul Barrette on 8 Oct 2023
Thanks, the cyclist. I didn't think of approaching it that way, but it works. It's also versatile - I'll use this method in other places.
Huw
Huw on 9 Apr 2024
Personally I find it a little easier to set it up so that the next row title is defined by one of the Axes' title.
So I have indivdiually labeled axes with their subtitle, and use either the first/middle axes object on the row to set a title for the whole row.

Sign in to comment.

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!