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

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

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

Initial import of Stark code.

Line 
1
2         function [hplot,hleg] = patchplot(varargin)
3
4 %
5 %   PATCHPLOT plots up to three sets of data as patches on a current axis
6 %
7 %   PATCHPLOT requires the following arguments:
8 %               data (up to 3)  - array in the format [x y q]
9 %                                 where q is the scalar to be displayed
10 %               leg (opt)       - string of legend text
11 %                                 if leg1 specified, legends must
12 %                                 be specified for all input datasets
13 %               pctsc (opt)     - percent scale of axis for patch objects
14 %                                 (default is 2)
15 %                               
16 %   [hplot,hleg] = patchplot(data1, leg1, data2, leg2, data3, leg3, pctsc);
17 %   [hplot,hleg] = patchplot(data1, data2, data3, pctsc);
18 %   [hplot,hleg] = patchplot(data1, leg1, data2, leg2);
19 %
20 % Calls: none
21 %
22 %  Catherine R. Edwards
23 %  Last modified: 12 Apr 2000
24 %
25
26
27 % PROCESS THE INPUT ARGUMENTS -- Copy incoming cell array
28 input_cell=varargin;
29 nargs=length(input_cell);
30
31 % DEFINE ERROR STRINGS
32 err1=['Incorrect number of arguments to PATCHPLOT'];
33 err2=['Each set of data must have a legend.'];
34 err3=['Incorrect ordering of arguments.'];
35
36 % Length of input_cell must be between 1 and 7, inclusive.
37 if nargs<1 |  nargs>7
38    error(err1)
39 end
40
41 % Set num patches and part out input_cell
42 if nargs==1
43   npatch=1; data1=input_cell{1};
44 elseif nargs==2
45   npatch=1; data1=input_cell{1};
46   if isstr(input_cell{2})
47     leg1=input_cell{2};
48   elseif prod(size(input_cell{2}))<2
49     pctsc=input_cell{2};
50   else
51     npatch=2; data2=input_cell{2};
52   end
53 elseif nargs==3
54   if isstr(input_cell{2})
55     npatch=1;data1=input_cell{1}; leg1=input_cell{2}; pctsc=input_cell{3};
56   elseif prod(size(input_cell{3}))==1
57     npatch=2;data1=input_cell{1};data2=input_cell{2}; pctsc=input_cell{3};
58   else
59     npatch=3; data1=input_cell{1}; data2=input_cell{2}; data3=input_cell{3};
60   end
61 elseif nargs==4
62   npatch=1; data1=input_cell{1}; 
63   if isstr(input_cell{2})
64     npatch=2; leg1=input_cell{2}; data2=input_cell{3}; leg2=input_cell{4};
65   else
66     npatch=3; data2=input_cell{2}; data3=input_cell{3}; pctsc=input_cell{3};
67   end
68 elseif nargs==5
69   npatch=2; data1=input_cell{1}; leg1=input_cell{2};
70   data2=input_cell{3}; leg2=input_cell{4}; pctsc=input_cell{5};
71 elseif nargs==6
72   npatch=3; data1=input_cell{1}; leg1=input_cell{2}; data2=input_cell{3};
73   leg2=input_cell{4}; data3=input_cell{5}; leg3=input_cell{6};
74 else
75   npatch=3; data1=input_cell{1}; leg1=input_cell{2}; data2=input_cell{3};
76   leg2=input_cell{4}; data3=input_cell{5}; leg3=input_cell{6};
77   pctsc=input_cell{7};
78 end
79
80 if ~exist('pctsc'); pctsc=2; end
81 if isstr(pctsc); error(err3); end
82 if ~exist('leg1'); nargout=1;
83  end
84
85 % SCALE VELOCITY DATA TO RENDERED WINDOW SCALE
86
87 RLs= get(gca,'XLim');xr=RLs(2)-RLs(1);
88 RLs= get(gca,'YLim');yr=RLs(2)-RLs(1);
89
90 if(xr==0|yr==0)
91    error('Axes must have been previously set for PATCHPLOT to work');
92 end
93 pct=0.5*pctsc*sqrt(xr*xr+yr*yr)/100;
94
95 % arrange data
96
97 if isempty(data1); else;
98   s1=size(data1); if s1(1)~=3; data1=data1'; end
99   x1=data1(1,:); y1=data1(2,:); q1=data1(3,:); Q=q1;
100   xsqr1=x1-pct; xsqr2=x1+pct; xsqr3=0.5*(xsqr1+xsqr2);
101   ysqr1=y1-pct; ysqr2=y1+pct; ysqr3=0.5*(ysqr1+ysqr2);
102   xsqr=[xsqr1; xsqr2; xsqr2; xsqr1]; ysqr=[ysqr1; ysqr1; ysqr2; ysqr2];
103   hold on;
104 end
105 hbox=plot(5,5,'sb','visible','off');
106
107 if npatch>=2
108   if isempty(data2); else;
109     s2=size(data2); if s2(1)~=3; data2=data2'; end
110     x2=data2(1,:); y2=data2(2,:); q2=data2(3,:); Q=[q1 q2];
111     xtri1=x2-pct; xtri2=x2+pct; xtri3=0.5*(xtri1+xtri2);
112     ytri1=y2-pct; ytri2=y2+pct; ytri3=0.5*(ytri1+ytri2);
113     xtri=[xtri1; xtri2; xtri3]; ytri=[ytri1; ytri1; ytri2];
114   end
115   htr=plot(1,1,'^b','visible','off');
116 end
117 if npatch==3
118   if isempty(data3); else;
119     s3=size(data3); if s3(1)~=3; data3=data3'; end
120     x3=data3(1,:); y3=data3(2,:); q3=data3(3,:);Q=[q1 q2 q3];
121     pct=sqrt(2)*pct;            % make diamond xy a little bigger
122     xdia1=x3-pct; xdia2=x3+pct; xdia3=0.5*(xdia1+xdia2);
123     ydia1=y3-pct; ydia2=y3+pct; ydia3=0.5*(ydia1+ydia2);
124     xdia=[xdia3; xdia2; xdia3; xdia1]; ydia=[ydia1; ydia3; ydia2 ;ydia3];
125   end
126   hdb=plot(7,7,'db','visible','off');
127 end
128
129 cl=[fix(10*min(Q))/10 ceil(10*max(Q))/10];
130 hsqr=patch(xsqr,ysqr,q1); set(gca,'clim',cl);
131 if npatch>=2
132   htri=patch(xtri,ytri,q2); set(gca,'clim',cl);
133 end
134 if npatch==3
135   hdia=patch(xdia,ydia,q3); set(gca,'clim',cl);
136 end
137 colorbar;
138
139 % assign handles to plots
140
141 if npatch==1
142   hplot=hsqr;
143   if exist('leg1');
144     hleg=legend(hbox,leg1);
145   end
146 elseif npatch==2
147   hplot=[hsqr,htri];
148   if exist('leg1');
149     if ~isstr(leg2); error(err2); end
150     hleg=legend([hbox,htr],leg1,leg2);
151   end
152 elseif npatch==3
153   hplot=[hsqr,htri,hdia];
154   if exist('leg1');
155     if ~isstr(leg2) | ~isstr(leg3); error(err2); end
156     hleg=legend([hbox,htr,hdb],leg1,leg2,leg3);
157   end
158 end
159
160 return;
Note: See TracBrowser for help on using the browser.