Adjusting the legend spacing
이전 댓글 표시
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])
채택된 답변
추가 답변 (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])
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

