Title. I need to find a way to pan and zoom two axes which overlap each other while maintaining their aspect ratios. I'm essentially using the second axes in the top-right position as a ruler with a different unit of measurement. I have tried such solutions as linkprop, linkaxes; and even community solutions like addaxes, addaxis, and linkzoom. Unfortunately, these do not provide a solution to my problem. Code can be found in the attachment or copy-pasted from below. Many thanks.
%% create figure
h = figure;%% create axes
% first axes
ax1 = axes('units','pixels',... 'nextplot','replacechildren');xlabel('seconds');ylabel('meters');% reference axes
ax2 = axes('units','pixels',... 'nextplot','replacechildren',... 'Position',ax1.Position,... 'XAxisLocation','top',... 'YAxisLocation','right',... 'Color','none');xlabel('milliseconds');ylabel('kilometers');%% create test data
% starting data
meters = cumsum(rand(15,1));seconds = cumsum(rand(15,1));%% plotting
% plot data
plot(ax1,meters,seconds);% update reference axes limits
set(ax2, 'xlim', ax1.XLim*1000);set(ax2, 'ylim', ax1.YLim/1000);%% the problem
% need to find a way to pan and zoom both axes at the same time while
% maintaining their respective aspect ratios, linkaxes fails here since it
% links their limits, breaking zoom functionality
% linkaxes([ax1,ax2],'xy');
Best Answer