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

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

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

Initial import of Stark code.

Line 
1 %
2 % VECPLOTSTICK vecplotstick(x,y,u,v,sc,color,dotsize)
3 %
4 %            routine to plot vectors.  STICKPLOT scales the magnitude of
5 %            (u,v) by the magnitude of max(abs(u,v)) and then
6 %            to Q percent of the range of the domain (xin,yin) coordinates. 
7 %            Initially, Q is 10.  The input argument sc scales Q. 
8 %            If sc=1, Q=10.  If sc=2, Q=20. If sc=.5, Q=5.
9 %
10 %            STICKPLOT overlays on existing axes, regardless of the state
11 %            of 'hold'.  If there is no current axes, STICKPLOT draws a
12 %            new axes.
13 %         
14 %            x,y     - vector origins
15 %            u,v     - vector amplitudes
16 %            sc      - vector scale; use '1' first time.
17 %            color   - stick color; (optional, def = 'r')
18 %            dotsize - vector origin "dot" size (optional, def = 10)
19 %
20 %            dotsizes are given in points where a point is 1/72 inches
21 %            The MATLAB default MarkerSize of 6 is approx. the size of a .
22 %            (period).
23 %
24 %            Example call:  stickplot(x,y,u,v,2,'r',10)
25 %            This will draw vectors at (x,y) with appropriately scaled
26 %            magnitudes (u,v), with the maximum vector size being 20
27 %            percent of the domain exent, with red lines used
28 %            to draw the vectors, and with vector origin dots being
29 %            10 points wide. 
30 %
31 %            NOTES:
32 %            STICKPLOT requires atleast 2 points and vectors.
33 %            STICKPLOT does NOT force the axis aspect ratio to be 1:1.
34 %
35 %
36 % Calls: none
37 % Call as:   hp=vecplotstick(x,y,u,v,sc,color,dotsize);
38 %
39 function  retval=vecplotstick(xin,yin,uin,vin,sc,...
40                               vcolor,ds,sclab,scale_xor,scale_yor)
41 %
42 % Argument check
43 %
44 if nargin<5
45    error('VECPLOTSTICK must have atleast 5 input arguments; type "help stickplot"');
46 elseif nargin == 5
47    vcolor='k';
48    ds=10;
49 elseif nargin == 6
50    if ~isstr(vcolor)
51       error('color argument to VECPLOTSTICK not a string');
52    end
53    ds=10;
54 elseif nargin > 10
55    error('Too many input arguments; type "help stickplot"');
56 end
57
58 if ~isstr(vcolor)
59    error('color argument to VECPLOTSTICK not a string');
60 end
61
62
63 if length(xin)~=length(yin) | length(xin)~=length(uin) | length(xin)~=length(vin)
64    error('Length of x,y,u,v must be the same');
65 end
66 if length(xin)==1
67    error('Length of x,y,u,v must be greater than 1');
68 end
69
70 xin=xin(:);
71 yin=yin(:);
72 uin=uin(:);
73 vin=vin(:);
74
75 % SCALE VELOCITY DATA TO RENDERED WINDOW SCALE
76 %
77 RLs= get(gca,'XLim');
78 xr=RLs(2)-RLs(1);
79 X1=RLs(1);
80 X2=RLs(2);
81 RLs= get(gca,'YLim');
82 yr=RLs(2)-RLs(1);
83 Y1=RLs(1);
84 Y2=RLs(2);
85 % IF RenderLimits NOT SET, USE RANGE OF DATA
86 %
87 if(xr==0|yr==0)
88    error('Axes must have been previously set for VECPLOT2 to work');
89 end
90 pct10=xr/10;
91 %FILTER DATA THROUGH VIEWING WINDOW
92 %
93 filt=find(xin>=X1&xin<=X2&yin>=Y1&yin<=Y2);
94 x=xin(filt);
95 y=yin(filt);
96 u=uin(filt);
97 v=vin(filt);
98 % SCALE BY MAX VECTOR SIZE IN U AND V
99 %
100 us=u/sc;
101 vs=v/sc;
102 % SCALE TO 10 PERCENT OF X RANGE
103 %
104 us=us*pct10;
105 vs=vs*pct10;
106
107 % SEND VECTORS TO DRAWSTICK ROUTINE
108 %
109 hp=drawstick(xin,yin,us,vs,ds,vcolor);
110 set(hp(1),'UserData',[xin yin uin vin]);
111 set(hp,'Tag','vectors');
112
113 mainax=gca;
114 % Draw vector scale
115 data_axis=axis;
116 cur_units=get(gca,'Units');
117 set(gca,'Units','normalized');
118 axnorm=get(gca,'Position');
119 xstart=axnorm(1)+axnorm(3)*.8;
120 ystart=axnorm(2);
121 dx=axnorm(3)*.2;
122 dy=axnorm(4)*.1;
123 %scale_axes=axes('Units','normalized','Position',[xstart ystart dx dy]);
124 scale_axes=axes('Units','normalized','Position',[0 0 dx dy]);
125 set(scale_axes,'XTick',[],'YTick',[])
126 set(scale_axes,'Tag','vecscaleaxes');
127 set(scale_axes,'ButtonDownFcn','movescaleaxes(1)');
128 dx1=data_axis(1)+(data_axis(2)-data_axis(1))*.8;
129 dx2=data_axis(2);
130 dy1=data_axis(3);
131 dy2=data_axis(3)+(data_axis(4)-data_axis(3))*.1;
132 axis([dx1 dx2 dy1 dy2])
133 sc_or_x=dx1+(dx2-dx1)/10;
134 ht1=drawstick(sc_or_x,(dy1+dy2)/2.05,pct10,0.,10,vcolor);
135 set(ht1,'Tag','scalearrow');
136 sctext=[num2str(sc) sclab];
137 scaletext=text((dx1+dx2)/2,(dy1+dy2)/1.95,sctext);
138 set(scaletext,'HorizontalAlignment','center');
139 set(scaletext,'VerticalAlignment','middle');
140 set(scaletext,'Tag','scaletext');
141 drawnow
142 axes(mainax)
143 set(scale_axes,'Visible','on')
144
145 % OUTPUT HANDLES IF DESIRED
146 %
147 if nargout==1,retval=hp;,end
148
149 %
150 %        Brian O. Blanton
151 %        Department of Marine Sciences
152 %        15-1A Venable Hall
153 %        CB# 3300
154 %        Uni. of North Carolna
155 %        Chapel Hill, NC
156 %                 27599-3300
157 %
158 %        919-962-4466
159 %        blanton@cuda.chem.unc.edu
160 %
Note: See TracBrowser for help on using the browser.