function plotEnsemble(t,y1,y2,y3,fig, t_min, t_max, lbl)
% plotEnsemble(t,y1,y2,y3, fig, t_min, t_max, lbl)

 m1 = size(y1,1);
 m2 = size(y2,1);
 m3 = size(y3,1);
 m  = max([m1,m2,m3]);

 N  = length(t);
 dt = t(2)-t(1);

 max1 = max(max(y1)); min1 = min(min(y1));
 max2 = max(max(y2)); min2 = min(min(y2));
 max3 = max(max(y3)); min3 = min(min(y3));

 yMax = max([max1,max2,max3]);
 yMin = min([min1,min2,min3]);
 y_range = 0.7*abs( yMax - yMin );
 ly = round(y_range);

 figure(fig)
 clf
 yTickVal = [];
 yTickLbl = {};
 hold on
    for ii=1:m
      dy = -y_range*(ii-1);
      plot([t(1) t(N)], [0 0]+dy,'--k', 'LineWidth',1.5);
      if ~isempty(y1)
        plot ( t,y1(ii,:)+dy, '-', 'color', [0,0.2,0.8], 'MarkerSize', 2.5 );
      end
      if ~isempty(y2)
        plot ( t,y2(ii,:)+dy, '-', 'color', [0,0.8,0.2], 'LineWidth',2.5 ); 
     end
      if ~isempty(y3)
        plot ( t,y3(ii,:)+dy, '-', 'color', [0.8,0.2,0.8], 'LineWidth',2.0 ); 
      end

      text(t_min, dy+y_range/7, sprintf('%s_%d',lbl,ii),'FontSize',14,'FontWeight','Bold');

      yTickVal = [ yTickVal , dy-ly/3 , dy , dy+ly/3 ];
      yTickLbl{3*ii-2} = sprintf('%4.1f ',-ly/3);
      yTickLbl{3*ii-1} = sprintf('%3.0f ',0); 
      yTickLbl{3*ii-0} = sprintf('%4.1f ', ly/3);
    end
    set(gca,'YTick', yTickVal);
    set(gca,'YTickLabel', yTickLbl);
    set(gca,'clipping','off');
    %axis('ticxy');
    axis([ t_min, t_max, -(m-0.5)*y_range, +0.5*y_range ]);

    for ii=1:m    % min and max of each record.   

      dy = -y_range*(ii-1);

%     [ymin,imin] = min(y1(ii,:));
%     [ymax,imax] = max(y1(ii,:));
%     text(imin*dt,ymin+dy,sprintf('%+5.0f',ymin));
%     text(imax*dt,ymax+dy,sprintf('%+5.0f',ymax));
%     plot(imin*dt,ymin+dy,'ok');
%     plot(imax*dt,ymax+dy,'ok');

      [ymin,imin] = min(y2(ii,:));
      [ymax,imax] = max(y2(ii,:));
      text(imin*dt,ymin+dy,sprintf('%+5.0f',ymin));
      text(imax*dt,ymax+dy,sprintf('%+5.0f',ymax));
      plot(imin*dt,ymin+dy,'ok');
      plot(imax*dt,ymax+dy,'ok');

%     [ymin,imin] = min(y3(ii,:));
%     [ymax,imax] = max(y3(ii,:));
%     text(imin*dt,ymin+dy,sprintf('%+5.0f',ymin));
%     text(imax*dt,ymax+dy,sprintf('%+5.0f',ymax));
%     plot(imin*dt,ymin+dy,'ok');
%     plot(imax*dt,ymax+dy,'ok');
    end
 
 hold off

