Adjusting the legend spacing
Mostrar comentarios más antiguos
I have slightly lengthy legend titles as shown in the figure below. Is there a way to adjust the location of 'a val' / 'b val' more towards the centre of their title name (move leftwards)?
Similarly for 'c limit' /'d limit' ( move towards right!!)
The sample code used to generate the plot is given below
a=rand(1,10);
b=rand(1,10);
c=ones(1,10)*0.7;
d=ones(1,10)*0.2;
figure;
p1=plot(a,'o-r');
hold on
p2=plot(b,'s-b');
p3=plot(c,'-.k');
p4=plot(d,'-.k');
lg=legend([p1 p2 p3 p4],'a val','b val','c limit','d limit');
lg.NumColumns=2;
title(lg,'raw data values from experiments limitation values');
ylim([0 1.2])
Respuesta aceptada
Más respuestas (1)
Not directly answering your question, but a different (and more conventional) approach would be to move the limit annotations out of the legend.
rng default
a=rand(1,10);
b=rand(1,10);
figure
hold on
p1=plot(a,'o-r');
p2=plot(b,'s-b');
yline(0.7,'-.')
yline(0.2,'-.')
text(9,0.675,'d limit')
text(9,0.175,'c limit')
lg=legend([p1 p2],{'a','b'});
title('raw data values from experiments');
ylim([0 1.2])
1 comentario
Shivaprasad Shridhara Bhat
el 25 de Nov. de 2021
Categorías
Más información sobre Legend en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

