MATLAB: How to limit zoom to one of the axes of one plot on a figure containing multiple plots

axesMATLABoneselectedsubplotszoom

I have a GUIDE-generated figure with two axes. Zooming works well, but I want to limit the zooming to only one of the two axes (subplots), enabling zooming for one of the axes while disabling it for the other axes.

Best Answer

It is possible to selectively enable or disable zooming for axes using the Zoom Mode Utility Functions.
The setAllowAxesZoom function can be used for this purpose.
For example, the following code generates plots with two axes and enables the zoom only for the first one.
ax1 = subplot(2,1,1);
plot(1:10);
h = zoom;
ax2 = subplot(2,1,2);
plot(rand(3));
setAllowAxesZoom(h,ax2,false);
To learn more about the Zoom Mode Utility Functions, please refer to the documentation page for the ZOOM function. To access the documentation, execute the following at the MATLAB command prompt.
doc zoom