フィルターのクリア

Fixed-distance of legend outside plot axes

15 ビュー (過去 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 Center および File ExchangeLegend についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by