How to position the legend and legend box at my required place in the figure?

14 views (last 30 days)
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.

Accepted Answer

Marc Jakobi
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).

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!