"Restore View" limits come from... where?
71 views (last 30 days)
Show older comments
I'm having some difficulty with a plot in Matlab 2018b. After plotting the data, I select the "Zoom In" option from the axes menu on the top-right, and zoom in and out to inspect the data. I later select "Restore View" from the context menu available when using "Zoom In", expecting it to go back to what it was after I plotted the data. However, I end up with a blank white axes with XLim [0 1]. (Legitimate X limits would be along the lines of [7.3705e+05 7.3740e+05].) Manually setting the X limits reveals that my data plots are still there, but well out of view.
My question is: Where is Matlab getting the limits that should be used when performing "Restore View"?
If needed, here's some more detailed information:
I am using a stack of two axes, directly overlaid on top of each other, inside of a graphics panel. The two axes are linked on the X-axis ("linkaxes([a,b],'x');"). The "upper" axes are set to have no background color, and "PickableParts" has been set to none.
Accepted Answer
Walter Roberson
on 2 Mar 2019
Look in zoom.m function getbounds(), about line 1074. It is axes appdata zoom_zomOrigAxesLimits that it pulls out to make sure you do not zoom out too far.
With you having two axes, then I would worry about the expected axes being the active axes.
3 Comments
Walter Roberson
on 26 Jun 2019
Sorry, I have only looked at the very surface of how appdesigner works.
More Answers (1)
breathi
on 17 May 2021
Edited: breathi
on 17 May 2021
Since this thread is in the top search results for linkaxes as well, here is a related article for linkaxes from MathWorks: https://www.mathworks.com/matlabcentral/answers/426098-zoom-auto-doesn-t-work-with-linkaxes-when-data-is-replaced
So for linkaxes, the easiest solution is to restore the auto mode for Lim:
% ax is an Axes array
% link x axes of all plots
linkaxes(ax,'x');
% reset XLimMode back to auto to properly "Restore View" when data is
% exchanged
[ax.XLimMode] = deal('auto');
In other cases, Walter is right. Here some more information.
From my info, "Restore View" finally triggers
resetplotview
which is an internal function. A more common function to restore the view is
zoom out;
For R2021a, the appdata change can be seen in localResetPlotView():
edit(fullfile(matlabroot, 'toolbox', 'matlab', 'graphics', 'resetplotview.m'))
So basically, the standard view of an axes can be found with
getappdata(ax)
And as Walter suggested, look for "zoom_zoomOrigAxesLimits". If it is not set, the axes view has not yet been modified by zoom/pan. Changing the limit property also doesn't set a "Restore View" point.
To manually set the "Home" zoom of an axes (https://www.mathworks.com/matlabcentral/answers/345743-how-can-i-change-the-default-original-view-that-a-figure-resets-to-when-i-double-click-inside-the-fi), use
zoom reset;
To delete the "Home" zoom of an axes (https://www.mathworks.com/matlabcentral/answers/23318-reset-to-original-view-with-zoom), use
resetplotview(ax,'InitializeCurrentView');
% or possibly remove the zoom data fields:
rmappdata(ax, 'zoom_zoomOrigAxesLimits');
rmappdata(ax, 'matlab_graphics_resetplotview');
0 Comments
See Also
Categories
Find more on Maintain or Transition figure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!