フィルターのクリア

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 Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by