UIAxes - zoom previous functionality.
8 ビュー (過去 30 日間)
古いコメントを表示
Hi All,
I've created an app with integrated UIAxes plot. That is working as expected.
I have added 3 zoom buttons with callbacks to update XLim and YLim.
- 'Zoom Auto': resets the zoom to the extents of the data.
- 'Zoom Old': resets the axis limits to the previous manual zoomed/panned location.
- 'Zoom Tip': zooms to a predefined location of the plot.
The way I have written it, when zoom auto, or tip buttons are pressed, the current XLim and YLim values are saved to XlimOld and YLimOld to be recalled later.
Auto and Tip zooms are working perfectly. the new X and Y limits are set and the ticks recalculate automatically.
When pressing Zoom Old, sometimes it works perfectly, other times, the ticks and positions are not recalculated.
So I thought the problem might occur when dynamically saving the current manual zoom position, but when I debug this seems to work correctly. So maybe this is a timing issue??
I have also tried moving the saveXYLim(app) code directly into the relevent callback functions, but the same problem occurs.
I'm pretty stuck on this which I thought was going to be a simple quality of life improvement for the app.
Any suggestions would be gladly received.
See below for the relevent snippets of code from appDesigner.
TIA,
Mark.
properties (Access = public)
XLimOld = [0,1]; % placeholder
YLimOld = [0,1]; % placeholder
XLimTip = [0,1]; % placeholder
YLimTip = [0,1]; % placeholder
end
methods (Access = private)
% save previous plot zoom location to restore later.
function saveXYLimOld(app)
% only save current axis limits if zoom is manual and not equal to the
% tip position.
if all([strcmp(app.UIAxes.XLimMode,'manual'),...
app.UIAxes.XLim ~= app.XLimTip,...
app.UIAxes.YLim ~= app.YLimTip])
app.XLimOld = app.UIAxes.XLim;
app.YLimOld = app.UIAxes.YLim;
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: ZoomTipButton
function ZoomTipButtonPushed(app, event)
% save previous plot zoom location to restore later.
saveXYLimOld(app)
% zoom to Tip location
app.UIAxes.XLim = app.XLimTip;
app.UIAxes.YLim = app.YLimTip;
end
% Button pushed function: ZoomOldButton
function ZoomOldButtonPushed(app, event)
% zoom to last manual zoomed location.
app.UIAxes.XLim = app.XLimOld;
app.UIAxes.YLim = app.YLimOld;
end
% Button pushed function: ZoomAutoButton
function ZoomAutoButtonPushed(app, event)
% save previous plot zoom location to restore later.
saveXYLimOld(app)
% reset zoom
app.UIAxes.XLimMode = 'auto';
app.UIAxes.YLimMode = 'auto';
end
end
0 件のコメント
回答 (1 件)
Praveen Reddy
2023 年 2 月 15 日
編集済み: Praveen Reddy
2023 年 2 月 17 日
Hi MC,
I Understand that you want to restore the last manually zoomed/panned axis limits. I have verified your code and checked that the buttons are working as expected. I reproduced a similar context and didn’t see any timing issues either. Please try updating your MATLAB to the latest version in case you face any issues.
5 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!