Legend with multiple columns and problem with alignement for last entry

18 visualizaciones (últimos 30 días)
Dear matlab comunity,
I used the legend property "NumColumns=2" to get 2 colums in my legend. However, I would like the last (longer) entry NOT to affect the alignment of the upper ones ("c" and "d"). Is there a possibility to do this?

Respuestas (1)

Star Strider
Star Strider el 6 de Feb. de 2024
There does not appear to be anying in Legend Properties that would directly address that problem. The only approach I can think of would be to break up ‘Long sentence’ into more than one line. This reduces the gap, however it would not completely eliminate it.
You can do that easily enough with the sprintf function —
x = 0:0.01:1;
y = sin((1:5).'*2*pi*x);
figure
plot(x, y(1,:), 'DisplayName','a')
hold on
plot(x, y(2,:), 'DisplayName','b')
plot(x, y(5,:), 'DisplayName',sprintf('%s\n%s','Long','sentence'))
plot(x, y(3,:), 'DisplayName','c')
plot(x, y(4,:), 'DisplayName','d')
hold off
legend('Location','best', 'NumColumns',2)
.

Categorías

Más información sobre Legend en Help Center y File Exchange.

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by