필터 지우기
필터 지우기

Fixed-distance of legend outside plot axes

조회 수: 13 (최근 30일)
Luca Carlino
Luca Carlino 2024년 2월 20일
편집: Matt J 2024년 2월 20일
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?

채택된 답변

Matt J
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개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by