NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/plots/shade_line.m

Revision 495 (checked in by cbc, 11 years ago)

Initial import of Stark code.

Line 
1 function hpatch=shade_line(x,y,color,y0)
2 %SHADE_LINE - shade a line object about a horizontal line
3 %   SHADE_LINE shades a line about a horizontal line.
4 %
5 %    INPUT :  x,y  - data abcissa and ordinate
6 %             c    - optional color in [R G B] or 'c' form
7 %                    default = [.75 .75 .75] (gray)
8 %             y0   - optional horizontal line about which
9 %                    to shade. default = y=0;
10 %   OUTPUT :  hpatch - handle to patch object drawn.
11 %
12 %     CALL :  hpatch=shade_line(x,y,c,y0);
13 %
14 % Calls: none
15 %
16 % Written by : Brian O. Blanton
17 % Spring 1999
18
19 if nargin<2 | nargin>4
20   error('Wrong number of arguments to SHADE_LINE')
21 end
22 %
23 % Assume 1-d data
24 x=x(:);
25 y=y(:);
26 if length(x)~=length(y)
27   error('Lengths of x,y must be equal')
28 end
29
30 if nargin==2
31   color=[1 1 1]*.75;
32   y0=0;
33 else
34    if isstr(color)
35       if length(color)~=1
36          error('Color string to SHADE_LINE must be ''r'', ...')
37       end
38       if nargin==3
39          y0=0;
40       else
41          [m,n]=size(y0);
42          if m*n~=1
43            error('Size of y0 must be 1x1')
44          end
45       end
46    else
47       [m,n]=size(color);
48       if m*n==1   % Assume this is y0
49         y0=color;
50         color=[1 1 1]*.75;
51       elseif m*n~=3
52         error('Size of color vector must be 1x3')
53       end
54       if max(color)>1 | min(color)<0
55          error('RGB colors must be >0 & <1')
56       end
57    end
58    if nargin==3,y0=0;,end
59    if nargin==4
60       [m,n]=size(y0);
61       if m*n~=1
62         error('Size of y0 must be 1x1')
63       end
64    end
65 end
66
67 % patch data
68 px=zeros(1,length(x)+2);
69 py=zeros(size(px));
70 px(2:length(px)-1)=x;
71 py(2:length(px)-1)=y;
72 % Connect end points with y=0;  % y0 should be input
73 px(length(px))=x(length(x));
74 py(length(py))=y0;
75 px(1)=x(1);
76 py(1)=y0;
77
78 hp=patch(px,py,color);
79
80 if nargout==1,hpatch=hp;,end
81
82 %
83 %        Brian O. Blanton
84 %        Department of Marine Sciences
85 %        15-1A Venable Hall
86 %        CB# 3300
87 %        Uni. of North Carolina
88 %        Chapel Hill, NC
89 %                 27599-3300
90 %
91 %        919-962-4466
92 %        blanton@marine.unc.edu
93 %
94 %        Spring 1999
95 %
Note: See TracBrowser for help on using the browser.