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

17 次查看(过去 30 天)
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.

采纳的回答

Marc Jakobi
Marc Jakobi 2016-10-5
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 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by