How to save changes to XLim so they are maintained when the user hits 'Restore View'/Home button

25 views (last 30 days)
Hello,
I have a figure that was generated by a different function, and I am overlaying additional data on top of it. Because of the new data I have added, I need to change the XLim properties in permanent, non-volatile way.
I have changed the setting on Property Inspector and saved the figure, but if I hit the "Restore View" button (which uses a home as its icon), it resets the XLim back to the values from when the figure was initially created.
I cannot recreate the figure from scratch, as I do not have all the source data, so is there a way to permanently modify a figure's default view options?

Answers (2)

Mario Malic
Mario Malic on 20 Nov 2025 at 21:22
Hello there,
It's been a while since I have seen a figure window, but can you make your x-axis limits to be manual?
xlim("manual")
After you add new data, pressing home should not change the limits.
Hope it helps.
  1 Comment
Chris
Chris on 20 Nov 2025 at 23:11
The XLim is already set to manual in the property inspector, unfortunately. That is where I am editing the XLim values I want set, as well.

Sign in to comment.


dpb
dpb on 23 Nov 2025 at 17:43
Edited: dpb on 24 Nov 2025 at 16:56
Try
newXlim=[x1 x2]; % the new limits desired
hAx=gca;
hAx.Xlim=newXLim; % set the observed limits
hAx.InteractionOptions.RestoredXLimits=hAx.XLim; % and then the restored valuees to match new
If using the interactive stuff (I never do), the interactive options may not be visible as they're supposed to be what the Home button reverts to so Mathworks probably figures they shouldn't be changed in order to be able to "unzoom", etc.
See if can set to the value you want to maintain after setting the new limits will break the old behavior. Note the above property doesn't exist until R2022b and later; before it is totally internal, not just a hidden/undocumented property.
At the moment I'm involved with a packaged app that was built with R2021b on a locked-down-by-IT system for the local community college so isn't convenient to try to test locally...

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!