Borrar filtros
Borrar filtros

UIAxes - zoom previous functionality.

4 visualizaciones (últimos 30 días)
MC
MC el 1 de Feb. de 2023
Editada: MC el 17 de Feb. de 2023
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.
  1. 'Zoom Auto': resets the zoom to the extents of the data.
  2. 'Zoom Old': resets the axis limits to the previous manual zoomed/panned location.
  3. '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

Respuestas (1)

Praveen Reddy
Praveen Reddy el 15 de Feb. de 2023
Editada: Praveen Reddy el 17 de Feb. de 2023
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 comentarios
MC
MC el 17 de Feb. de 2023
I have also just tried setting
xtickformat(app.UIAxes,'%.2f');
ytickformat(app.UIAxes,'%.2f');
so that the plot bounding box does not change size.
This has not helped either.
MC
MC el 17 de Feb. de 2023
Editada: MC el 17 de Feb. de 2023
I have simplified the plot to just a sine wave.
The issue remains.
function ButtonPlotRefreshPushed(app, event)
x = 1:360;
y = 180*sind(x);
plot(app.UIAxes,x,y)
app.UIAxes.DataAspectRatio = [1 1 1];
app.UIAxes.PlotBoxAspectRatio = [1 1 1];
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
app.UIAxes.YAxisLocation = 'right';
app.UIAxes.TickDir = 'out';
xtickformat(app.UIAxes,'%.2f');
ytickformat(app.UIAxes,'%.2f');
if app.CheckBoxPlotFlipSag.Value
app.UIAxes.YDir = 'reverse';
else
app.UIAxes.YDir = 'normal';
end
app.UIAxes.XLabel.String = 'X: Radial Position, mm';
app.UIAxes.YLabel.String = 'Z: Sag, mm';
% save tip position.
tipRange = 1;
app.XLimTip = [90-tipRange, 90+tipRange];
app.YLimTip = [180-tipRange, 180+tipRange];
end

Iniciar sesión para comentar.

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by