CLTEXT Places contour level text in the current window CALL: [h,ax] = cltext(levels,pl) h,ax = handles to the lines of text and the axes, respectively. levels = vector of contour levels or the corresponding percent which the contour line encloses pl = 0 if levels are the actual contour levels (default) 1 if levels are the corresponding percent which the contour line encloses CLTEXT creates new axes in the current figure and prints "Level curves at:" if pl==0 and "Level curves enclosing:" otherwise NOTE: -The handles to the lines of text and the axes may also be found by h = findobj(gcf,'tag','cltxt','type','text'); ax = findobj(gcf,'tag','cltxt','type','axes'); -If axis square command moves the cltext outside the figure box then oax = gca; axes(ax); axis square; axes(oax); may be used to restore the look. Examples: z=peaks;cl=max(z(:))-range(z(:))*(.1:.1:.9);contour(z,cl), cltext(cl) data = wraylrnd(1,2000,2); f = kdebin(data,'epan',[],[],.5,128); contour(f.x{:},f.f,f.cl),cltext(f.pl,1) See also figtext, pdfplot
Places text in figure window. | |
Create axes in arbitrary positions. | |
Delete file or graphics object. | |
Display message and abort function. | |
Create figure window. | |
Find objects with specified property values. | |
Get handle to current axis. | |
Get handle to current figure. | |
Get object properties. | |
True for white space characters. | |
Convert number to string. (Fast version) | |
Set object properties. | |
Vertically concatenate strings. | |
Text annotation. |
Plot contents of pdf structures |
001 function [H,nax] = cltext(clevels,PL) 002 %CLTEXT Places contour level text in the current window 003 % 004 % CALL: [h,ax] = cltext(levels,pl) 005 % 006 % h,ax = handles to the lines of text and the axes, respectively. 007 % levels = vector of contour levels or the corresponding percent which the 008 % contour line encloses 009 % pl = 0 if levels are the actual contour levels (default) 010 % 1 if levels are the corresponding percent which the 011 % contour line encloses 012 % 013 % CLTEXT creates new axes in the current figure and prints 014 % "Level curves at:" if pl==0 and 015 % "Level curves enclosing:" otherwise 016 % 017 % NOTE: -The handles to the lines of text and the axes may also be found by 018 % h = findobj(gcf,'tag','cltxt','type','text'); 019 % ax = findobj(gcf,'tag','cltxt','type','axes'); 020 % -If axis square command moves the cltext outside the figure box then 021 % oax = gca; axes(ax); axis square; axes(oax); 022 % may be used to restore the look. 023 % 024 % Examples: 025 % z=peaks;cl=max(z(:))-range(z(:))*(.1:.1:.9);contour(z,cl), cltext(cl) 026 % 027 % data = wraylrnd(1,2000,2); f = kdebin(data,'epan',[],[],.5,128); 028 % contour(f.x{:},f.f,f.cl),cltext(f.pl,1) 029 % 030 % See also figtext, pdfplot 031 032 033 034 % History 035 % revised pab Feb2004 036 % made it work with zoom to some extent 037 % revised pab Jan2004 038 % changed todo comments: (+) -> TODO 039 % revised pab 22.05.2000 minor changes 040 % revised pab 28.01.2000 041 % - prints the text in a separate axes in order to make the printed 042 % text independent of the scaling of the rest of the figure etc. 043 % adopted from pdfplot 044 045 % TODO % should be changed to work in the same way as legend does. 046 if nargin<1|isempty(clevels) 047 return % nothing to do 048 end 049 if nargin<2|isempty(PL) 050 PL=0; 051 elseif prod(size(PL))>1 052 error('pl must bea scalar: 0 or 1') 053 end 054 055 cax = gca; % get current axes 056 cfig = get(cax,'Parent'); % get current figure 057 figold = gcf; 058 if figold~=cfig, 059 figure(cfig); 060 end 061 062 % delete cltext object if it exists 063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 064 nax = findobj(cfig,'tag','cltxt'); % find if any cltxt has been made before 065 if ~isempty(nax), 066 % delete old cltext if it exists 067 delete(nax), 068 end 069 070 % create new axes for cltext 071 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% 072 073 cpos = get(cax,'position'); % current size of axes 074 heigth = cpos(4)*1/4; 075 newpos = [cpos(1) cpos(2)+2.9*heigth cpos(3)/2 heigth]; 076 nax = axes('Position',newpos,'box','off','Visible','off','tag', ... 077 'cltxt'); 078 %,'climmode',get(cax,'climmode'),'clim',get(cax,'clim')); %new axes 079 080 081 textstart_x = 0.036; 082 textstart_y = 0.94; 083 delta_y = 2/33; 084 085 if (PL==1), 086 h1=figtext(textstart_x,textstart_y,'Level curves enclosing:','norm','norm'); 087 else 088 h1=figtext(textstart_x,textstart_y,'Level curves at:','norm','norm'); 089 end 090 set(h1,'FontWeight','Bold','tag','cltxt') 091 092 textstart_y = textstart_y - delta_y; 093 094 cltxt=num2str(clevels(:),4); 095 if 1, % removing spaces in front of each line 096 [indx indy]=find(isspace(cltxt)); 097 for ix=indx(:).' 098 cltxt=strvcat(cltxt(1:ix-1,:),cltxt(ix,~isspace(cltxt(ix,:))),cltxt(ix+1:end,:) ); 099 end 100 end 101 h2 = figtext(textstart_x,textstart_y,cltxt,'norm','norm','left','top'); 102 set(h2,'tag','cltxt') 103 if nargout>0 104 H=[h1 h2]; 105 end 106 107 % create DeleteProxy objects (an invisible text object in 108 % the first axes) so that the other axes will be deleted 109 % properly. 110 DeleteProxy(1) = text('parent',cax,'visible','off',... 111 'tag','cltxtDeleteProxy',... 112 'handlevisibility','off',... 113 'deletefcn','eval(''delete(get(gcbo,''''userdata''''))'','''')'); 114 DeleteProxy(2) = text('units','normalized','parent',nax,'visible','off',... 115 'tag','cltxtDeleteProxy',... 116 'handlevisibility','off',... 117 'deletefcn','eval(''delete(get(gcbo,''''userdata''''))'','''')'); 118 set(DeleteProxy(1),'userdata',nax);%get(cfig,'children'));%nax); 119 set(DeleteProxy(2),'userdata',DeleteProxy(1)); 120 121 122 % reset to the old state 123 %%%%%%%%%%%%%%%%%%%%%%%%%% 124 set(cfig,'currentaxes',cax(1)) 125 126 if figold~=cfig, 127 figure(figold); 128 end 129 130 return
Comments or corrections to the WAFO group