Positioning of legend, Version 2025.0.0

Given a plot command under subplot - with rendering by isoview, data_bounds, tight_limits, and xtitle - the positioning of legend by axes coordinates seems to be disturbed. The documentation recommended way

as=get(gcf(),“axes_size”);//size of the canvas in pixels
bnds=get(gca(),“axes_bounds”);//bounds of the current axes rectangle in figure size ratio.
//from user coordinates to legend coordinates
[x1,y1]=xchange(x_user,y_user,‘f2i’)
position=[(x1-as(1)*bnds(1))/(as(1)*bnds(3)),…
(y1-as(2)*bnds(2))/(as(2)*bnds(4))];

is not effective, whereby I understand position as the input coordinates for legend. The legend command is inserted as the last one acting on the subplot.
What can I do better?

Hi Jens

Noone came to your assitance. Could you maybe post more complete but still minimal code, something that executes without errors?

The provided code fails with a bunch of ‘Undefined variable:’ errors.

With kind regards,
Claus

It looks like

gca().axes_bounds = [0.5, 0.5, 0.5, 0.5]; instead of [0.5, 0.5, 0.48, 0.5];

repair the positioning of legend. gca() is a 2x2 subplot.
Conversion between user coordinates an legend coordinates seem to be superflous.

Kind regards
Jens