필터 지우기
필터 지우기

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

조회 수: 53 (최근 30일)
Paul Barrette
Paul Barrette 2023년 10월 6일
댓글: Huw 2024년 4월 9일
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')

채택된 답변

the cyclist
the cyclist 2023년 10월 6일
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
Paul Barrette
Paul Barrette 2023년 10월 8일
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 2024년 4월 9일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by