Fixed-distance of legend outside plot axes
44 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Luca Carlino
am 20 Feb. 2024
Bearbeitet: Matt J
am 20 Feb. 2024
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 Kommentare
Akzeptierte Antwort
Matt J
am 20 Feb. 2024
Bearbeitet: Matt J
am 20 Feb. 2024
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!