Home > timeplt > timeplt.m

timeplt

PURPOSE ^

TIMEPLT time series stack plots with Gregorian Time labels on x axes

SYNOPSIS ^

function [h]=timeplt(jd,u,istack,ylims);

DESCRIPTION ^

 TIMEPLT  time series stack plots with Gregorian Time labels on x axes
   
      type timeplt('demo') for a demonstration or

      USAGE:  
          [h]=timeplt(jd,u,[istack],[ylims]);
      where
         jd = Julian Day time vector  (e.g produced by JULIAN.M)
         u = column vector or matrix of column vectors containing time
             series data.  If the column is complex, it will be plotted
             as a stick plot.  
         istack = vector of indices indicating which panel you want
             to plot the time series data.  istack=[1 2] would make
             two panels one on top of the other and plot the first 
             column of u in the lower panel and the second column of
             u in the upper panel.  If any column in u is complex,  
             istack must be specified.  If istack is not specified, all the 
             columns will be plotted in the first panel.
         ylims  = [npanels x 2] matrix containing the ylimits of 
              the panel plots.  If you are plotting two panels and 
              you want the limits of both plots to be from -10 to 15,
              then set ylims=[-10 15; -10 15].  Autoscales if ylims
              is not set

       outputs:
            h = handles for stack plots (axes)


 requires GREGAXD, GREGAXM, GREGAXH, GREGAXY, GREGORIAN, JULIAN, and
          STACKLBL

 Rich Signell rsignell@usgs.gov

 8-29-94 fixed bug in stick orientation 
 8-30-94 fixed problem with upper panel too close to top of figure
 11-1-94 eliminated ylabels from the argument list.  Just use the
         axes handles returned by timeplt to change axes and then
         use the standard "ylabel" command.
 12-4-96 replaced vector stick plotting method from lots of 2 point
         objects to 1 object with nans.  Much faster plotting.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [h]=timeplt(jd,u,istack,ylims);
0002 % TIMEPLT  time series stack plots with Gregorian Time labels on x axes
0003 %
0004 %      type timeplt('demo') for a demonstration or
0005 %
0006 %      USAGE:
0007 %          [h]=timeplt(jd,u,[istack],[ylims]);
0008 %      where
0009 %         jd = Julian Day time vector  (e.g produced by JULIAN.M)
0010 %         u = column vector or matrix of column vectors containing time
0011 %             series data.  If the column is complex, it will be plotted
0012 %             as a stick plot.
0013 %         istack = vector of indices indicating which panel you want
0014 %             to plot the time series data.  istack=[1 2] would make
0015 %             two panels one on top of the other and plot the first
0016 %             column of u in the lower panel and the second column of
0017 %             u in the upper panel.  If any column in u is complex,
0018 %             istack must be specified.  If istack is not specified, all the
0019 %             columns will be plotted in the first panel.
0020 %         ylims  = [npanels x 2] matrix containing the ylimits of
0021 %              the panel plots.  If you are plotting two panels and
0022 %              you want the limits of both plots to be from -10 to 15,
0023 %              then set ylims=[-10 15; -10 15].  Autoscales if ylims
0024 %              is not set
0025 %
0026 %       outputs:
0027 %            h = handles for stack plots (axes)
0028 %
0029 %
0030 % requires GREGAXD, GREGAXM, GREGAXH, GREGAXY, GREGORIAN, JULIAN, and
0031 %          STACKLBL
0032 %
0033 % Rich Signell rsignell@usgs.gov
0034 %
0035 % 8-29-94 fixed bug in stick orientation
0036 % 8-30-94 fixed problem with upper panel too close to top of figure
0037 % 11-1-94 eliminated ylabels from the argument list.  Just use the
0038 %         axes handles returned by timeplt to change axes and then
0039 %         use the standard "ylabel" command.
0040 % 12-4-96 replaced vector stick plotting method from lots of 2 point
0041 %         objects to 1 object with nans.  Much faster plotting.
0042 %
0043 
0044 %-------------------------------------------------------------------
0045 %  Set the cutoff for different types of Gregorian axis types
0046 %  You can adjust these to suit your preferences.  For example, if your
0047 %  plot got labeled with days, but you want hours, increase "daycut"
0048 %  (until it's larger than the "fac" for your plot).
0049   
0050   yearcut=250;
0051   moncut=20;
0052   daycut=.2;
0053   mincut=0.05;
0054 %
0055 if strcmp(jd,'demo')
0056   help timeplt
0057   start=[1990 11 1 0 0 0];    %Gregorian start [yyyy mm dd hh mi sc]
0058   stop=[1991 2 1 0 0 0];
0059   jd=julian(start):julian(stop); 
0060   u=sin(.1*jd(:)).^2-.5;
0061   v=cos(.1*jd(:));
0062   w=u+i*v;
0063 %w is vector, so must have it's own axes
0064   h=timeplt(jd,[u v abs(w) w],[1 1 2 3]); 
0065   title('Demo of Timeplt')
0066   stacklbl(h(1),'East + North velocity','m/s');
0067   stacklbl(h(2),'Speed','m/s');
0068   stacklbl(h(3),'Velocity Sticks','m/s');
0069   return
0070 end
0071 
0072 
0073 %
0074 % Don't clip that data!
0075 set(0,'DefaultLineclipping','off')
0076 
0077 [m,n]=size(u);
0078 if(m==1),u=u(:);m=n;n=1;end; %if row vector, make column vec
0079 clf
0080 if(~exist('istack')),
0081   istack=ones(n,1);
0082 end
0083 njd=length(jd);
0084 jd0=jd(1);
0085 jd1=jd(njd);
0086 ndays=jd1-jd0;
0087 %
0088 % determine how many stack plots to make
0089 %
0090 nstack=max(istack);
0091 % determine height of each stack plot
0092 hstack=.70/nstack;
0093 xmin=.13;
0094 ymin=.15;
0095 width=0.77;
0096 h(1)=axes('position',[xmin ymin width hstack]);
0097 set(gca,'units','pixels');...
0098 pos=get(gca,'pos');
0099 xlen=pos(3);
0100 ylen=pos(4);...
0101 font=get(gca,'fontsize');...
0102 label_width=5*font;
0103 nlabel=floor(xlen/label_width);
0104 set(gca,'units','normalized');
0105 fac=ndays/nlabel;  %number of days per label
0106 % adjust xfactor for subsequent stretching by Gregorian Date
0107   if( fac > yearcut),
0108     xlim=[jd0-180 jd1+180];
0109   elseif(yearcut > fac & fac > moncut),
0110     xlim=[jd0-15 jd1+15];
0111   elseif(moncut > fac & fac > daycut),
0112     xlim=[floor(jd0)-.5 ceil(jd1)+.5];
0113   elseif(daycut > fac & fac > mincut);
0114     xlim=[jd0-1/48 jd1+1/48];
0115   elseif(mincut > fac);
0116     
0117     %
0118     % leave 2.5% off of each side.
0119     time_offset = (jd1-jd0)*0.025;
0120     xlim=[jd0-time_offset jd1+time_offset];
0121   end
0122 up=u(:,find(istack==1));
0123 if(isreal(up)),
0124   h2=plot(jd,up);... 
0125   if(exist('ylims')),
0126     set(gca,'ylim',ylims(1,:));...
0127   end
0128 else
0129   if(exist('ylims')),
0130     ylim=ylims(1,:);
0131   else
0132     y0=min(gmin(imag(up(:))),0);
0133     y1=max(gmax(imag(up(:))),0);
0134     ylim=[y0 y1];
0135   end
0136   set(gca,'units','pixels');
0137   ppos=get(gca,'position');
0138   set(gca,'units','norm');
0139   d=diff(xlim);
0140   uscale=(diff(xlim)/diff(ylim))*(ppos(4)/ppos(3));
0141   vp=imag(up);
0142   up=uscale.*real(up);
0143   x=jd;
0144   xp=x;
0145   yp=zeros(size(xp));
0146   xplot=ones(length(xp),2);
0147   yplot=xplot;
0148   xplot(:,1)=x(:);
0149   xplot(:,2)=xp(:)+up(:);
0150   xplot(:,3)=x(:);
0151   yplot(:,1)=yp(:);
0152   yplot(:,2)=yp(:)+vp(:);
0153   yplot(:,3)=yp(:)*nan;
0154   xplot=xplot';
0155   yplot=yplot';
0156   if(~isempty(find(finite(up(:))))),
0157    plot([jd0 jd1],[0 0],'r-',xplot(:),yplot(:),'r-');...
0158   set(gca,'ylim',ylim);
0159   end
0160 end
0161 set(gca,'xlim',xlim);
0162 if( fac > yearcut),
0163   gregaxy(jd,floor(fac/yearcut));
0164 elseif(yearcut >= fac & fac>moncut),
0165   gregaxm(jd,floor(fac/moncut));
0166 elseif(moncut >= fac & fac>daycut),
0167   gregaxd(jd,ceil(fac));
0168 elseif(daycut >= fac & fac> mincut);
0169   gregaxh(jd,max(1,floor(fac*48)));
0170 elseif(mincut >= fac);
0171   gregaxmi(jd,max(1,floor(fac*120*24)));
0172 end
0173 if(nstack==1),return,end
0174 pos_norm=get(gca,'position');
0175 vsep=1.3*font*pos_norm(4)/pos(4);
0176 for iplot=2:nstack,
0177   h(iplot)=axes('position',[xmin ymin+(hstack+vsep)*(iplot-1) width hstack]);
0178   up=u(:,find(istack==iplot));
0179 if(isreal(up)),
0180   plot(jd,up);
0181   if(exist('ylims')),
0182     set(gca,'ylim',ylims(iplot,:))
0183   end
0184 else
0185   if(exist('ylims')),
0186     ylim=ylims(iplot,:);
0187   else
0188     y0=min(0,gmin(imag(up(:))));
0189     y1=max(0,gmax(imag(up(:))));
0190     ylim=[y0 y1];
0191   end
0192   set(gca,'units','pixels');
0193   ppos=get(gca,'position');
0194   set(gca,'units','norm');
0195   d=diff(xlim);
0196   uscale=(diff(xlim)/diff(ylim))*(ppos(4)/ppos(3));
0197   vp=imag(up);
0198   up=uscale.*real(up);
0199   x=jd;
0200   xp=x;
0201   yp=zeros(size(xp));
0202   xplot=ones(length(xp),2);
0203   yplot=xplot;
0204   xplot(:,1)=x(:);
0205   xplot(:,2)=xp(:)+up(:);
0206   xplot(:,3)=x(:);
0207   yplot(:,1)=yp(:);
0208   yplot(:,2)=yp(:)+vp(:);
0209   yplot(:,3)=yp(:)*nan;
0210   xplot=xplot';
0211   yplot=yplot';
0212   if(~isempty(find(finite(up(:))))),
0213   plot([jd0 jd1],[0 0],'r-',xplot(:),yplot(:),'r-');...
0214   set(gca,'ylim',ylim);
0215   end
0216 end
0217   set(gca,'xlim',xlim,'xtick',get(h(1),'xtick'),'xticklabels',[]);
0218 end
0219 set(0,'DefaultLineclipping','on')

Generated on Wed 30-Nov-2005 15:41:21 by m2html © 2003