Reputation: 69
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 attached here
Note: The data shown below are completely representative. I am not keen on finding ways to replot this dataset differently to illustrate the same idea. The aim is to adjust the legend location.
% random variables
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])
Upvotes: 3
Views: 651
Reputation: 754
This is some kind of ugly last-resort solution, but what worked for me was switching the interpreter to latex and then using latex commands to add additional space.
lg=legend([p1 p2 p3 p4], ['a val \hspace{50pt}' ],'b val','c limit','d limit');
lg.Interpreter = 'latex';
Please note, that this changes also the font.
Upvotes: 1