v_texthvc

PURPOSE ^

V_TEXTHVC - write text on graph with specified alignment and colour

SYNOPSIS ^

function h=v_texthvc(x,y,t,p,q,r)

DESCRIPTION ^

V_TEXTHVC - write text on graph with specified alignment and colour

Usage: (1) v_texthvc(x,y,'Hello','mlr')          % align centre-baseline colour=red
       (2) v_texthvc(x,y,'\alpha','ml',[1 0 0])  % align centre-baseline colour=red
       (3) v_texthvc(x,y,'Hello','Mlr')          % x position is normalized to (0,1)
       (4) v_texthvc([x k],y,'Hello','mlr')      % add k*axis-width onto the x position

 Inputs:  x  x-position of text in graph coordinates (or normalized see below)
             alternatively x=[x0 k] positions at x0 + k*axis-width
          y  y-position of text in graph coordinates (or normalized see below)
             alternatively y=[y0 k] positions at y0 + k*axis-height
          t  text string to write on graph. Use \alpha for greek or x_1 for subscript
          p  3-character text string, 'hvc' specifying:
               horizontal reference point, h: l=left, c or m=middle, r=right
               vertical reference point,   v: t=top, p=cap, c or m=middle, l=baseline, b=bottom
               colour,                     c: in 'rgbcmykw'
          q  alternative colour specification as [r g b] each in range 0 to 1
          r  obselete (included only for legacy compatibility)

 If the horizontal or vertical reference point is given as a capital
 letter, the corresponding position is normalized to the axis range
 and should be in the range 0 to 1.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function h=v_texthvc(x,y,t,p,q,r)
0002 %V_TEXTHVC - write text on graph with specified alignment and colour
0003 %
0004 %Usage: (1) v_texthvc(x,y,'Hello','mlr')          % align centre-baseline colour=red
0005 %       (2) v_texthvc(x,y,'\alpha','ml',[1 0 0])  % align centre-baseline colour=red
0006 %       (3) v_texthvc(x,y,'Hello','Mlr')          % x position is normalized to (0,1)
0007 %       (4) v_texthvc([x k],y,'Hello','mlr')      % add k*axis-width onto the x position
0008 %
0009 % Inputs:  x  x-position of text in graph coordinates (or normalized see below)
0010 %             alternatively x=[x0 k] positions at x0 + k*axis-width
0011 %          y  y-position of text in graph coordinates (or normalized see below)
0012 %             alternatively y=[y0 k] positions at y0 + k*axis-height
0013 %          t  text string to write on graph. Use \alpha for greek or x_1 for subscript
0014 %          p  3-character text string, 'hvc' specifying:
0015 %               horizontal reference point, h: l=left, c or m=middle, r=right
0016 %               vertical reference point,   v: t=top, p=cap, c or m=middle, l=baseline, b=bottom
0017 %               colour,                     c: in 'rgbcmykw'
0018 %          q  alternative colour specification as [r g b] each in range 0 to 1
0019 %          r  obselete (included only for legacy compatibility)
0020 %
0021 % If the horizontal or vertical reference point is given as a capital
0022 % letter, the corresponding position is normalized to the axis range
0023 % and should be in the range 0 to 1.
0024 
0025 %      Copyright (C) Mike Brookes 2014
0026 %      Version: $Id: v_texthvc.m 10865 2018-09-21 17:22:45Z dmb $
0027 %
0028 %   VOICEBOX is a MATLAB toolbox for speech processing.
0029 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0030 %
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 %   This program is free software; you can redistribute it and/or modify
0033 %   it under the terms of the GNU Lesser General Public License as published by
0034 %   the Free Software Foundation; either version 3 of the License, or
0035 %   (at your option) any later version.
0036 %
0037 %   This program is distributed in the hope that it will be useful,
0038 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0039 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0040 %   GNU Lesser General Public License for more details.
0041 %
0042 %   You can obtain a copy of the GNU Lesser General Public License from
0043 %   https://www.gnu.org/licenses/ .
0044 %    See files gpl-3.0.txt and lgpl-3.0.txt included in this distribution.
0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0046 
0047 if nargin<3
0048     error('<3 arguments');
0049 elseif nargin>6
0050     error('>6 arguments');
0051 end
0052 
0053 switch nargin
0054     case 3
0055         h=text(x,y,char(t));
0056     case 6
0057         % for compatibility with old version
0058         h=text(x,y,char(t),'HorizontalAlignment',p,'VerticalAlignment',q,'Color',r);
0059     otherwise
0060         if nargin==5
0061             r=q; % color specification
0062         elseif nargin==4
0063             r=p(3:end);  % colour is at end of spec string
0064         end
0065         ix=find(lower(p(1))=='lcmr',1);
0066         if isempty(ix)
0067             error('invalid horizontal spec');
0068         end
0069         iy=find(lower(p(2))=='tpcmlb',1);
0070         if isempty(iy)
0071             error('invalid vertical spec');
0072         end
0073         vx={'left', 'center', 'center', 'right'};
0074         vy={'top', 'cap', 'middle', 'middle', 'baseline', 'bottom'};
0075         if numel(x)>1
0076             if strcmpi(get(gca,'xscale'),'log')
0077                 x=exp(log(x(1))+log(get(gca,'xlim'))*[-1; 1]*x(2));
0078             else
0079                 x=x(1)+get(gca,'xlim')*[-1; 1]*x(2);
0080             end
0081         else
0082             if p(1)==upper(p(1))
0083                 if strcmpi(get(gca,'xscale'),'log')
0084                     x=exp(log(get(gca,'xlim'))*[1-x; x]);
0085                 else
0086                     x=get(gca,'xlim')*[1-x; x];
0087                 end
0088             end
0089         end
0090         if numel(y)>1
0091             if strcmpi(get(gca,'yscale'),'log')
0092                 y=exp(log(y(1))+log(get(gca,'ylim'))*[-1; 1]*y(2));
0093             else
0094                 y=y(1)+get(gca,'ylim')*[-1; 1]*y(2);
0095             end
0096         else
0097             if p(2)==upper(p(2))
0098                 if strcmpi(get(gca,'yscale'),'log')
0099                     y=exp(log(get(gca,'ylim'))*[1-y; y]);
0100                 else
0101                     y=get(gca,'ylim')*[1-y; y];
0102                 end
0103             end
0104         end
0105         h=text(x,y,char(t),'HorizontalAlignment',vx{ix},'VerticalAlignment',vy{iy},'Color',r);
0106 end

Generated by m2html © 2003