MATLAB Answers

Align the Legend Title to the Legend body

32 ビュー (過去 30 日間)
Sim
Sim 2020 年 9 月 14 日
コメント済み: Sim 2020 年 9 月 23 日
Hi, How can I align the Legend Title to the Legend body (variables, etc..)? Maybe left-aligned ?

  5 件のコメント

表示 2 件の古いコメント
Adam Danz
Adam Danz 2020 年 9 月 14 日
If you contact tech support, they will either suggest a workaround or they may put it on their list of things to improve.
Maybe there's an undocumented method I'm not aware of.
Sim
Sim 2020 年 9 月 14 日
Thanks a lot! Just submitted to the MATLAB support :)
Adam Danz
Adam Danz 2020 年 9 月 14 日
I'd be interesting in whatever you find.

サインインしてコメントする。

回答 (1 件)

Ayush Gupta
Ayush Gupta 2020 年 9 月 18 日
The legend title is by-default left aligned to legend body. Refer to the code below which generates the following picture and read the documentation on how to add legend title, here.
x = linspace(0,pi);
y1 = cos(x);
plot(x,y1)
hold on
y2 = cos(2*x);
plot(x,y2)
hold off
lgd = legend('cos(x)','cos(2x)');
title(lgd,'My Legend Title')

  6 件のコメント

表示 3 件の古いコメント
Sim
Sim 2020 年 9 月 23 日
Oh thanks a lot, I will try to download r2020b and check that feature :)
Btw, in case it work I should accept your answer, but there is not any button for it (its just besides Ayhus Gupta)
Adam Danz
Adam Danz 2020 年 9 月 23 日
I've checked since I made that comment and legend titles are not supported with the updated features.
In fact, I wrote a Community Highlights about these new features.
Title alignment is controlled by the new "TitleHorizontalAlignment" property of axes. Legends still do not have such a property.
Sim
Sim 2020 年 9 月 23 日
Oh cool, thanks a lot for highlighting that feature... So, if not working for the Legends, my MATLAB ticket opening was worth it :)

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by