MATLAB: How to zoom two axes of different scale by the same relative amount at the same time using the ZOOM tool in MATLAB 7.8 (R2008b)

axeslinkaxeslinkpropMATLABmultiple

I have two overlapping axes on the same figure. They are each at separate scales. I would like to zoom both axes by the same relative factor.

Best Answer

To do this with numeric axes, you will need to create a ZOOM object and set its ActionPostCallback method to a callback function that manually coordinates the two different axes limits.
As an example, see the attached file, CreateFigure.m, which includes code to perform this. To test it, try zooming into a section of the code and confirm that both axes zoom as expected.
The callback that was defined in this function is as follows:
 
function myzoom(obj,event_obj)
% obj handle to the figure that has been clicked on
% event_obj object containing struct of event data (same as the
% event data of the 'ActionPreCallback' callback)
ax = findobj(obj.figure, 'type','axes');
axes1 = ax(1); axes2 = ax(2);
axisvals = [get(axes1,'xlim'),get(axes1,'ylim')];
% Focus on bottom axes
set(axes2,'xlim',[pi/180*axisvals(1:2)]);
set(axes2,'ylim',axisvals(3:4));