How to position the legend and legend box at my required place in the figure?
14 views (last 30 days)
Show older comments
Thanigaivel Raja T
on 4 Oct 2016
Answered: Marc Jakobi
on 5 Oct 2016
This is my code for the legend section of my figure.
[w,hO]=legend({'a_{occ}','a_{exp}'},'Location','southeast','FontName','Arial','Fontsize',6,'FontWeight','bold');
set([hO(3),hO(5)],'Xdata',[0.6 0.7]);
legend boxon
set(gcf, 'paperunits', 'centimeters', 'paperposition', [0 0 7.5 5.625])
The figure I get as output is attached.
With regard to the figure, I want the legend to be placed anywhere between (x1,y1)=(130,-20) (x2,y2)=(145,-30) w.r.t my plot axis. I also want a legend box positioned surrounding it precisely.
What should be my code changes for this? Also explain how it would work?
Thanks in advance.
0 Comments
Accepted Answer
Marc Jakobi
on 5 Oct 2016
It will be difficult to determine the precise location automatically. You can manually position it using the 'Position' property. For example:
w.Position = [bottom, top, width, height];
The position values are normalized to the figure window's position by default (values between 0 and 1). By changing the bottom and top coordinates, you can move the legend to where you want it. By changing the width and height, you can change its size (and get the box to wrap around it precisely).
0 Comments
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!