Fixed-distance of legend outside plot axes

44 visualizaciones (últimos 30 días)
Luca Carlino
Luca Carlino el 20 de Feb. de 2024
Editada: Matt J el 20 de Feb. de 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?

Respuesta aceptada

Matt J
Matt J el 20 de Feb. de 2024
Editada: Matt J el 20 de Feb. de 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.

Más respuestas (0)

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by