MATLAB: Cannot zoom x axis properly with multiple 2D plots in same figure – linkprop

2dlinkaxeslinkpropmultiple axesmultiple plots

I cannot figure out how to get the x axis to zoom properly. Y axis works fine because all of the y data is the same scale. But because I am plotting different xlim per plot linkaxes just can seem to do it. I have tried working with linkprop to no avail either, although maybe the answer is buried in there somewhere. I tried to simplify my code for posting but thought you might as well get it all and the data too, so links are provided. Any insight is appreciated.
data.png = Link to my plot
data.mat = Link to my data
figure
axesPosition = [.032 .01 .955 .99];
axes('position',axesPosition,'xtick',[],'ytick',[],'xTickLabel',{},'yTickLabel',{});
h = [];
for i = 1:size(disColWant,2)-1 + size(ctdColWant,2)-1;
if i <= size(disColWant,2)-1;
h(i) = axes('position',axesPosition);
plot(h(i), disNumData(:,disColNum(:,i+1)),...
(disNumData(:,(disColNum(:,1))))*-1,...
'linestyle',Config.LineStyle.(disColWant{i+1}),...
'color',Config.Color.(disColWant{i+1}),...
'marker',Config.MarkerStyle.(disColWant{i+1}),...
'markersize',Config.MarkerSize);
set(gca,'xlim',Config.Scale.(disColWant{i+1}),...
'ylim',Config.Scale.(disColWant{1}),...
'visible','off');
else h(i) = axes('position',axesPosition);
plot(h(i),ctdNumData(:,ctdColNum(:,i-11)),...
(ctdNumData(:,(ctdColNum(:,1))))*-1,...
'linestyle',Config.LineStyle.(ctdColWant{i-11}),...
'color',Config.Color.(ctdColWant{i-11}),...
'marker',Config.MarkerStyle.(ctdColWant{i-11}),...
'markersize',Config.MarkerSize);
set(gca,'xlim',Config.Scale.(ctdColWant{i- 11}),...
'ylim',Config.Scale.(ctdColWant{1}),...
'visible','off');
end
end
linkaxes(h,'y')

Best Answer

Create a zoom mode object for the figure. Use a ButtonDownFilter to filter out requests that are not over any of the axes. Create a ActionPostCallback that figures out which axes was zoomed and then goes around to all of the other axes and does appropriate setting of the axes limits for them.
Or instead of using ButtonDownFilter and having to figure out which axes it was, you could (depending on what else you need to do) set HitTest off on all of the objects in all of the axes, leaving only a single axes (but not its children) with HitTest on. The zoom would then be known to be against that one axes, so you could skip the ButtonDownFilter and checking of which axes was touched and go ahead and set the xlim appropriately for all of the other axes.