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

25 ビュー (過去 30 日間)
Chris
Chris 2025 年 11 月 20 日 21:11
編集済み: dpb 2025 年 11 月 24 日 16:56
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?

回答 (2 件)

Mario Malic
Mario Malic 2025 年 11 月 20 日 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 件のコメント
Chris
Chris 2025 年 11 月 20 日 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.

サインインしてコメントする。


dpb
dpb 2025 年 11 月 23 日 17:43
編集済み: dpb 2025 年 11 月 24 日 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...

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by