Question
How to restrict zooming out of an image displayed in a UIAxes component beyond the original axes limits In a figure-based axes object, if you zoom out of an image displayed using "imshow", the zoom-out capability is restricted to axis limits corresponding to the size of the image. However, as of MATLAB R2020b for UIAxes, this is not the case and it allows zooming out beyond the original size of the image, thereby overshrinking the image. Is it possible to restrict this behavior and not allow the image to overshrink when zooming out?
Expert Answer
Kshitij Singh
PhD Expert
Answered Aug 16, 2026
One possible workaround to this would be to use the "ActionPostCallback" callback function for the zoom object corresponding to the UIAxes. Please take a look at the following example which illustrates the workaround. Here, every time the user tries to zoom out beyond the original axes limits, the limits are reset to the original value:
a=uiaxes;
imshow(imread('cameraman.tif'),'Parent',a);
origXLim=a.XLim;
origYLim=a.YLim;
% Listen to zoom events
h = zoom(a);
set(h,'ActionPostCallback',@(x,y)mypostcallback(x,y,origXLim,origYLim));
set(h,'Enable','on');
function mypostcallback(obj,evd,origXLim,origYLim)
newLim = get(evd.Axes,'XLim');
if (newLim(2)-newLim(1)) > (origXLim(2)-origXLim(1))
evd.Axes.XLim=origXLim;
evd.Axes.YLim=origYLim;
end
end
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related zoom Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →