Align the Legend Title to the Legend body

49 visualizaciones (últimos 30 días)
Sim
Sim el 14 de Sept. de 2020
Comentada: Gábor Holló el 11 de Oct. de 2024
Hi, How can I align the Legend Title to the Legend body (variables, etc..)? Maybe left-aligned ?
  6 comentarios
Adam Danz
Adam Danz el 14 de Sept. de 2020
I'd be interesting in whatever you find.
Gábor Holló
Gábor Holló el 11 de Oct. de 2024
A possible (not too elegant) workaround is to use the latex interpreter and shift the text manually. E.g.:
fplot(@(x)sin(x),[0,2*pi])
hl = legend('Our quite long legend to see the centering of the title','interpreter','latex');
title(hl,'Legend title \hspace{8 cm}','interpreter','latex')

Iniciar sesión para comentar.

Respuestas (1)

Ayush Gupta
Ayush Gupta el 18 de Sept. de 2020
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 comentarios
Adam Danz
Adam Danz el 23 de Sept. de 2020
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 el 23 de Sept. de 2020
Oh cool, thanks a lot for highlighting that feature... So, if not working for the Legends, my MATLAB ticket opening was worth it :)

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by