MATLAB R2025b “savefig(…)” fails to save changed legend Position when existing .fig file is opened and edited.
The question is explained in detail in the attached .txt file. Briefly:
Assume some figure A.fig was created by some plot(..) commands etc. and was then saved with only one single legend and legend box position coordinates [xO yO wO hO], the _old_ coordinates, with assumed values like, say,
[xO yO wO hO] == [0.7 0.6 0.2 0.3 .
From that A.fig, I now want to generate a new version, B.fig, which displays the legend box with _new_ position coordinate values, [xN yN wN hN], given by
[xN yN wN hN] == [0.6 0.5 0.3 0.4] ,
all else being the same as in A.fig.
The problem I run into is this:
I open A.fig, look up the legend handle (call it "hL") and change the legend box position coordinates by hL.Position=[xN yN wN hN]; hL.Location=’none’; save it as B.fig by savefig(‘B.fig’) and then close all. If I then later (re-)open B.fig, I find that B.fig has been saved with the old legend position coordinates [xO yO wO hO], instead of the new ones, [xN yN wN hN].The question is explained in detail in the attached .txt file. Briefly:
Assume some figure A.fig was created by some plot(..) commands etc. and was then saved with only one single legend and legend box position coordinates [xO yO wO hO], the _old_ coordinates, with assumed values like, say,
[xO yO wO hO] == [0.7 0.6 0.2 0.3 .
From that A.fig, I now want to generate a new version, B.fig, which displays the legend box with _new_ position coordinate values, [xN yN wN hN], given by
[xN yN wN hN] == [0.6 0.5 0.3 0.4] ,
all else being the same as in A.fig.
The problem I run into is this:
I open A.fig, look up the legend handle (call it "hL") and change the legend box position coordinates by hL.Position=[xN yN wN hN]; hL.Location=’none’; save it as B.fig by savefig(‘B.fig’) and then close all. If I then later (re-)open B.fig, I find that B.fig has been saved with the old legend position coordinates [xO yO wO hO], instead of the new ones, [xN yN wN hN]. The question is explained in detail in the attached .txt file. Briefly:
Assume some figure A.fig was created by some plot(..) commands etc. and was then saved with only one single legend and legend box position coordinates [xO yO wO hO], the _old_ coordinates, with assumed values like, say,
[xO yO wO hO] == [0.7 0.6 0.2 0.3 .
From that A.fig, I now want to generate a new version, B.fig, which displays the legend box with _new_ position coordinate values, [xN yN wN hN], given by
[xN yN wN hN] == [0.6 0.5 0.3 0.4] ,
all else being the same as in A.fig.
The problem I run into is this:
I open A.fig, look up the legend handle (call it "hL") and change the legend box position coordinates by hL.Position=[xN yN wN hN]; hL.Location=’none’; save it as B.fig by savefig(‘B.fig’) and then close all. If I then later (re-)open B.fig, I find that B.fig has been saved with the old legend position coordinates [xO yO wO hO], instead of the new ones, [xN yN wN hN]. changed legend, savefig fails MATLAB Answers — New Questions