reverse-shooting

Matlab scripts for reverse shooting
Log | Files | Refs | README

yylabels.m (3110B)


      1 function []=yylabels(ax,ylab1,ylab2,ytick1,ytick2,xtick);
      2 
      3 % function []=yylabels(ax,lab1,lab2);
      4 %
      5 % Creates "chadfig"-like labels for the y1 and y2 axes, after ax=plotyy()
      6 % has been called.
      7 %   -- assumes chadfig has already done ylab1 correctly...
      8 
      9 h1=get(ax(1),'YLabel');
     10 h2=get(ax(2),'YLabel');
     11 
     12 curaxis=axis(ax(1));
     13 
     14 if exist('xtick'); if ~isempty(xtick);  %XTickLabel
     15     set(ax(1),'XTickLabel',xtick);    
     16     set(ax(1),'XTick',str2num(xtick));
     17     curaxis(1)=min(str2num(xtick));
     18     curaxis(2)=max(str2num(xtick));
     19     axis(ax(1),curaxis);
     20 end; end;
     21 
     22 if exist('ytick1');  %YTickLabel
     23     set(ax(1),'YTickLabel',ytick1);    
     24     set(ax(1),'YTick',str2num(ytick1));
     25     curaxis(3)=min(str2num(ytick1));
     26     curaxis(4)=max(str2num(ytick1));
     27     axis(ax(1),curaxis);
     28 end;
     29 
     30 
     31 if ~iscell(ylab1);
     32   if ylab1(1)~=' ';
     33     % add spaces if needed to get centered position
     34     nn=length(ylab1);  
     35     if nn>8; ylab1=[ones(1,round(1.8*(nn-8)))*' ' ylab1]; end; %1.4 for 16pt, 1.8 for 18pt
     36   end;
     37 end;
     38 
     39 if iscell(ylab1);
     40     ylabel(ax(1),ylab1,'FontWeight','Bold','Rotation',0);
     41 else;
     42   if any(ylab1=='$');
     43     ylabel(ax(1),ylab1,'FontWeight','Bold','Rotation',0,'interpreter','latex');
     44     % Note, bold doesn't seem to work in latex model.  Use {\bf } in ylab1
     45   else;
     46     ylabel(ax(1),ylab1,'FontWeight','Bold','Rotation',0);
     47   end;
     48 end;
     49 
     50 pos=get(h1,'Position');
     51 step=curaxis(4)-curaxis(3);
     52 %newaxis=curaxis;
     53 %axis(newaxis);
     54 newloc=curaxis(4)+.02*step;  % .03 instead of 0.1
     55 pos(2)=newloc;
     56 set(h1,'Position',pos);
     57 set(h1,'HorizontalAlignment','center');
     58 set(h1,'VerticalAlignment','bottom');
     59 
     60 
     61 
     62 curaxis=axis(ax(2));
     63 
     64 if exist('xtick'); if ~isempty(xtick);  %XTickLabel
     65     set(ax(2),'XTickLabel',xtick);    
     66     set(ax(2),'XTick',str2num(xtick));
     67     curaxis(1)=min(str2num(xtick));
     68     curaxis(2)=max(str2num(xtick));
     69     axis(ax(2),curaxis);
     70 end; end;
     71 
     72 if exist('ytick2');  %YTickLabel
     73     set(ax(2),'YTickLabel',ytick2);    
     74     set(ax(2),'YTick',str2num(ytick2));
     75     curaxis(3)=min(str2num(ytick2));
     76     curaxis(4)=max(str2num(ytick2));
     77     axis(ax(2),curaxis);
     78 end;
     79 
     80 
     81 if ~iscell(ylab2);
     82   if ylab2(1)~=' ';
     83     % add spaces if needed to get centered position
     84     nn=length(ylab2);  
     85     if nn>8; ylab2=[ones(1,round(1.8*(nn-8)))*' ' ylab2]; end; %1.4 for 16pt, 1.8 for 18pt
     86   end;
     87 end;
     88 
     89 if iscell(ylab2);
     90     ylabel(ax(2),ylab2,'FontWeight','Bold','Rotation',0);
     91 else;
     92   if any(ylab2=='$');
     93     ylabel(ax(2),ylab2,'FontWeight','Bold','Rotation',0,'interpreter','latex');
     94     % Note, bold doesn't seem to work in latex model.  Use {\bf } in ylab2
     95   else;
     96     ylabel(ax(2),ylab2,'FontWeight','Bold','Rotation',0);
     97   end;
     98 end;
     99 
    100 pos=get(h2,'Position');
    101 step=curaxis(4)-curaxis(3);
    102 %newaxis=curaxis;
    103 %axis(newaxis);
    104 newloc=curaxis(4)+.07*step;  % .05*step
    105 pos(2)=newloc;
    106 set(h2,'Position',pos);
    107 set(h2,'HorizontalAlignment','right');
    108 set(h1,'VerticalAlignment','bottom');
    109 
    110 
    111 pos=get(get(ax(1),'XLabel'),'Position');
    112 pos(1)=curaxis(1)+(curaxis(2)-curaxis(1))/2;
    113 set(get(ax(1),'XLabel'),'Position',pos);
    114 set(get(ax(1),'XLabel'),'HorizontalAlignment','center');
    115 set(get(ax(1),'XLabel'),'VerticalAlignment','top');
    116