next up previous contents
Next: Plotting 3D surfaces Up: Appendix II: Other tips Previous: Colorbars   Contents

Plotting wind vectors

IDL has a facility to plot 2D fields of vectors. There is an example
in thehelp pages and one more below.

;Create random 2d fields of velocities in 2D
orig_sz=200
U = RANDOMN(S, orig_sz, orig_sz); u velocity m/s
V = RANDOMN(S, orig_sz, orig_sz); v velocity m/s
; Create arrays of array positions
ypos = (intarr(orig_sz)+1)#indgen(orig_sz) ; yposition (0-orig_sz-1)
xpos = indgen(orig_sz)#(intarr(orig_sz)+1) ; xposition (0-orig_sz-1)

; Sub-sampling is applied to avoid oversrowding the plot with arrows
; NB: This sub-sampling (to avoid too many arrows) is written for a 
; square array with the same sub-sampling in  x and y.
; What is the best way that you can find to generalise this? 
smple=10 ; sub-sampling frequency
plot_arr_u=U(where(xpos mod smple eq 0. and ypos mod smple eq 0.) )
plot_arr_v=V(where(xpos mod smple eq 0. and ypos mod smple eq 0.) )
; 'a mod b' returns the integer remainder of a/b
sz=size(plot_arr_u)
; Convert 1D vectors to 2D arrays
plot_arr_u=reform(plot_arr_u,sz(1)^.5,sz(1)^.5)
plot_arr_v=reform(plot_arr_v,sz(1)^.5,sz(1)^.5)

; Create plot
pos=[0.13,0.17,0.95,0.85]
!p.position=pos
set_plot,'x'
window,0,retain=2
VELOVECT,plot_arr_u,plot_arr_v



John Marsham 2009-12-07