Borrar filtros
Borrar filtros

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

53 visualizaciones (últimos 30 días)
Paul Barrette
Paul Barrette el 6 de Oct. de 2023
Comentada: Huw el 9 de Abr. de 2024
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')

Respuesta aceptada

the cyclist
the cyclist el 6 de Oct. de 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 comentarios
Paul Barrette
Paul Barrette el 8 de Oct. de 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 el 9 de Abr. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by