plotnamesym2.m (3159B)
1 % plotnamesym2.m Chad Jones, 30-Jan-2013 2 % 3 % Creates a plot using the names 'names' and symbols in the 4 % graph. 5 % 6 % namethese(i)==1 means show name for sure 7 8 function h=plotnamesym2(x,y,names,fsize,color,distx,disty,namethese,addols,markercolor); 9 10 if exist('fsize')~=1; fsize=9; end; 11 if exist('color')~=1; color=[0 .4 0]; end; 12 if exist('markercolor')~=1; markercolor='b'; end; 13 if isempty(color); color=[0 .4 0]; end; 14 if exist('addols')~=1; addols=0; end; 15 if exist('distx')~=1; distx=.2*std(x); end; 16 if exist('disty')~=1; disty=.2*std(y); end; 17 18 h=plot(x,y,'o','Color',markercolor,'MarkerFaceColor',markercolor,'MarkerSize',3); 19 N=length(x); 20 if exist('namethese')~=1; namethese=zeros(N,1); end; % namethese==1 means name for sure 21 22 23 % TicTacToe is 2x3 centered on the point 24 % Look for nearby dots to help decide label placement 25 rr=3; cc=2; 26 rc=zeros(rr,cc,N); 27 28 for i=1:N; % Check point by point 29 for r=1:3; % row 30 for c=1:2; % column 31 % Figure out the cell range xx1:xx2, yy1:yy2 32 if c==1; 33 xx1=x(i)-distx; xx2=x(i); 34 elseif c==2; 35 xx1=x(i); xx2=x(i)+distx; 36 end; 37 if r==1; 38 yy1=y(i)+.25*disty; yy2=y(i)+1.5*disty; 39 elseif r==2; 40 yy1=y(i)-.25*disty; yy2=y(i)+.25*disty; 41 elseif r==3; 42 yy1=y(i)-1.5*disty; yy2=y(i)-.25*disty; 43 end; 44 45 % Now count the # of points in that cell other than current 46 xN=x; xN(i)=[]; 47 yN=y; yN(i)=[]; 48 inx=(xx1<xN & xN<xx2); 49 iny=(yy1<yN & yN<yy2); 50 inhere=sum(inx.*iny ); 51 rc(r,c,i)=sum(inx.*iny ); 52 end; 53 end; 54 % rc(:,:,i) 55 end; 56 57 for i=1:N; 58 horiz='left'; vert='middle'; % default 59 skipname=0; 60 rc01=rc(:,:,i)>0; % Just focus on "occupied" vs "empty" 61 c1=sum(rc01(:,1)); 62 c2=sum(rc01(:,2)); 63 if c1<c2; 64 horiz='right'; 65 cc=1; % Pick the column with fewer conflicts 66 else; 67 horiz='left'; 68 cc=2; 69 end; 70 csum=min([c1 c2]); 71 if csum==3; skipname=1; indx=2; end; % all quadrants occupied 72 if csum==2; % Then find the single 0 73 indx=find(rc01(:,cc)==0); 74 end; 75 if csum==1; % Then two zeros 76 ione=find(rc01(:,cc)==1); % Find the single 1 77 if ione==1; indx=3; end; 78 if ione==2; indx=1; end; 79 if ione==3; indx=1; end; 80 end; 81 if csum==0; indx=2; end; 82 if indx==1; vert='bottom'; end; 83 if indx==2; vert='middle'; end; 84 if indx==3; vert='top'; end; 85 86 if ~skipname | namethese(i); 87 % txt=[' ' cutspace(names(i,:)) ' ']; 88 if iscell(names); 89 txt=[' ' names{i} ' ']; 90 else; 91 txt=[' ' cutspace(names(i,:)) ' ']; 92 end; 93 text(x(i),y(i),txt,'horizontal',horiz,'vertical',vert,'FontSize',fsize,'Color',color); 94 end; 95 % names(i,:) 96 % rc01 97 % horiz 98 % vert 99 % keyboard 100 end; 101 102 if addols>0; 103 hold on; 104 105 [b tstat sigma2 vcv rsq]=lstiny(y,[ones(length(x),1) x]); 106 se = b(2)/tstat(2); 107 bstr=sprintf('OLS Slope = %7.3f\n',b(2)); 108 sstr=sprintf(' Std. Err. = %7.3f\n',se); 109 rstr=sprintf(' R^2 = %7.2f\n',rsq); 110 111 yfit=[ones(length(x),1) x]*b; 112 [xmin,imin]=min(x); 113 [xmax,imax]=max(x); 114 plot([xmin xmax],yfit([imin imax]),'-'); 115 116 if addols==1; 117 putstr(bstr); 118 putstr(sstr); 119 putstr(rstr); 120 end; 121 122 end;