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

61 vues (au cours des 30 derniers jours)
Paul Barrette
Paul Barrette le 6 Oct 2023
Commenté : Huw le 9 Avr 2024 à 13:07
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')

Réponse acceptée

the cyclist
the cyclist le 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 commentaires
Paul Barrette
Paul Barrette le 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 le 9 Avr 2024 à 13:07
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by