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])

 채택된 답변

Image Analyst
Image Analyst 2021년 11월 25일

1 개 추천

I don't know of any way in the legend() function. You might try creating strings for your legends manually and put a \n at the end of the string or beginning of the string.
Alternatively make your own legend manually with the text() function and place them wherever you want.

추가 답변 (1개)

the cyclist
the cyclist 2021년 11월 25일

0 개 추천

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

Shivaprasad Shridhara Bhat
Shivaprasad Shridhara Bhat 2021년 11월 25일
Thanks alot @the cyclist for you effort. I am aware of this method.
I am particularly looking for ways to adjust the legend locations.

댓글을 달려면 로그인하십시오.

카테고리

제품

릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by