Fixed-distance of legend outside plot axes
44 次查看(过去 30 天)
显示 更早的评论
Suppose you have a figure with a legend placed outside, for example:
Legend = legend('Legend','Location','northoutside');
The vertical distance between the edge of the plot axes and the legend actually depends on the zoom level. Compare the attachments: fig1 (default zoom) with fig2 (zoomed a bit). Thus, it seems MATLAB automatically adjusts this vertical distance.
I don't want this behaviour. I would like the legend to stay precisely where it is initially positioned, regardless of what I do with axes/zoom.
Please note that:
1) the plot/axes should not be modified (all aspects ratios, etc., need to be left untouched);
2) the initial position of the legend should be left to be decided by MATLAB (not manually set, aside from the command: Location northoutside) - the wanted behaviour is that this position, once defined, should remain frozen in place.
Any help is kindly appreciated.
Additional question: is there any "simple" parameter (i.e., not position) which controls the vertical distance between the legend box and the upper edge of the axes?
0 个评论
采纳的回答
Matt J
2024-2-20
编辑:Matt J
2024-2-20
is there any "simple" parameter (i.e., not position) which controls the vertical distance between the legend box and the upper edge of the axes?
No. You will have to record the initial legend Position and the axis InnerPosition properties and readjust them to the relationship that you want. If you're saying you want this to happen automatically whenever you resize or zoom the plot, youwould have to set up a listener.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!