Saturday, July 10, 2010

Draw vector fields with gnuplot.

To plot a data file that contains motion vectors formated as
x1 y1 u1 v1
x2 y2 u2 v2
...
xN yN uN vN
where for each row (x,y) is the position of the vector and (u,v) is its magnitude, use the command

plot "motion_vectors.data" using 1:2:3:4  with vec


this plots small vectors at each position (x,y). 
If we want to plot only some of the points (because the field is dense) we use  the every 4:4 option, and scale the vectors by 4 


plot "motion_vectors.data" every 4:4 u 1:2:($3*4):($4*4) w vec

To overprint the vectors on an image (with gnuplot 4.2). The image must be stored as a binary file image.bin and the size of the image must be known 300x400.


plot "image.bin" binary array=300x400 flipy with image, "motion_vectors.data" every 12:12 u 1:2:($3*8):($4*8) w vec

Sometimes other adjustements are necesarry to the plots, just manipulate: ($1):($2):($3*8):($4*8)



References:
http://t16web.lanl.gov/Kawano/gnuplot/datafile2-e.html#7.6
http://www2.yukawa.kyoto-u.ac.jp/~ohnishi/Lib/gnuplot.html
http://gnuplot.sourceforge.net/demo/image.html

No comments:

Post a Comment