function [axout,h1,h2]=plotyy2(varargin)
% Simple wrapper around plotyy to make zoom behavior a little easier.
% See help plotyy for the correct syntax.
%
% Intruction of use: the resulting plot will automatically match the
% x-scales on the different plots generated by plotyy on RESIZE. That means
% that after zooming, resizing the figure fixes the zoom on the x axis.
%
% Just a very simple hack... by L.Cavin, 2005
[axout,h1,h2]=plotyy(varargin{:});
% find children axis, find the one that is behind (i.e. "unzoomed")
cmd = 'blop = findobj(gcf, ''Type'', ''axes''); idx = find(blop ~= gca);';
% set YLim to automatic in the "behind" plot:
cmd = [cmd 'set(blop(idx), ''YLimMode'', ''auto'');'];
% set some other "cosmetic" properties:
cmd = [cmd 'set(blop(idx), ''YTickMode'', ''auto'');'];
cmd = [cmd 'set(blop(idx), ''TickLength'', [0.01 0]);'];
cmd = [cmd 'set(gca, ''TickLength'', [0 0]);'];
% set the XLim of the "behind" plot to the ones of the "before" plot. Fix
% some other stuff:
cmd = [cmd 'set(blop(idx), ''XLim'', get(gca, ''XLim''));'];
set(gcf, 'Resizefcn', cmd);