How to have legend in multiple rows and center aligned?

8 ビュー (過去 30 日間)
Rounak Saha Niloy
Rounak Saha Niloy 2024 年 1 月 16 日
回答済み: Matt J 2024 年 1 月 16 日
I have the following code-
y=repmat([10,20,30,15,25],10,1);
bar(y,'stacked',LineStyle='none');
id=cellstr(num2str([1:size(y,2)].','A%d'));
h=legend(id,'Location','northoutside','Orientation','horizontal',FontSize=13)
This gives the output as-
I want to have the legend in two rows and center aligned at the northoutside.
How do I do that?
Note, I have tried -
h.NumColumns=2;
This gives-
What I want is like this-
A1 A2
A3 A4 A5.
Please note, these must be center aligned.

回答 (1 件)

Matt J
Matt J 2024 年 1 月 16 日
The second output of legendflex,
gives handles to the different text and patch objects situated in the legend. You could modify the positions to have the centered appearance that you describe.

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by