Matlab UIAxes "restore view" not using set X limits.

조회 수: 9 (최근 30일)
Sameer Gummuluru
Sameer Gummuluru 2021년 2월 17일
답변: Abhas 2025년 2월 24일
I have a tiled layout in my app with 2 axes with their x axes linked. I have disabled default interactivity and changed the toolbar to show only specific buttons.
app.tiledLayout = tiledlayout(app.plotPanel,2,1);
app.axes1 = nexttile(app.tiledLayout);
app.axes2 = nexttile(app.tiledLayout);
linkaxes([app.axes1 app.axes2],'x');
plot(app.axes1, time, data1)
plot(app.axes2, time, data2)
axtoolbar(app.axes1, {'zoomin','zoomout', 'restoreview'});
axtoolbar(app.axes2, {'zoomin','zoomout', 'restoreview'})
disableDefaultInteractivity(app.axes1)
disableDefaultInteractivity(app.axes2)
xlim(app.axes1, [0 60])
The plots appear as expected. However when I interact with the plots using toolbar buttons and try to reset the view using restoreview button, the x limits are being set to to the toal time range which is [0 600] rather than [0 60]. Is there anyway to make the view alway restore to [0 60]?
Thank you for the help.

답변 (2개)

phenan08
phenan08 2022년 5월 22일
I am facing the same issue and I do not understand why this is happening.
Should anyone have the right tip, feel free to share it!

Abhas
Abhas 2025년 2월 24일
To ensure that the 'Restore View' button always resets the x-axis to the limits set instead of the full data range, you can follow this workaround:
  • Create a Property in App Designer: Add a new private property in App Designer to store the default properties of the UIAxes component. Please note, you can create multiple such properties if you have more than one 'uiaxes' component.
properties (Access = private)
defaultAxesProperty; % To store required default properties of UIAxes component
end
  • Modify the 'startupFcn' Callback (if required): Store the required user defined properties of ‘uiaxes’ in ‘app.defaultAxesProperty’. For example, the ‘XLim’ property of UIAxes component can be stored as following:
app.defaultAxesProperty.XLim = app.UIAxes.XLim;
  • Replace the Default Axes Toolbar: Use the 'axtoolbar' function to create a custom axes toolbar, as the default toolbar cannot be modified in App Designer. The 'axtoolbar' function, can take 'app.UIAxes' component as first argument to set it as parent component and 'default' as the second argument. The function returns the toolbar object and the button objects created. The toolbar object can be ignored, and button objects can be stored in a variable 'btns'.
  • Override the 'Restore View' Button Behavior: Now btns(1) contains the 'Restore View' button of the custom axes toolbar. Attach a function to its 'ButtonPushedFcn' callback to restore UIAxes properties to the stored values. This callback is called when ‘Restore View’ button is pressed.
You may refer to the attached app, 'restoreView.mlapp' for the implemented workaround.
You may refer the below documentation and MATLAB Answers link to know more about the same:
  1. axtoolbar: https://www.mathworks.com/help/matlab/ref/axtoolbar.html
  2. https://www.mathworks.com/support/search.html/answers/447786-restore-view-limits-come-from-where.html
I hope this helps!

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by