Skip to content

D5. Vector fields ​

Goal: a velocity field as arrows, the body in the flow drawn as an object.

gnuplot
# a velocity field (flow.dat: x y u v) as arrows, the cylinder drawn as an object
set terminal svg size 600,420
set output 'pd05.svg'
set size ratio -1
set xrange [-3.5:3.5]; set yrange [-2.6:2.6]
set object 1 circle at 0,0 size 1 fc 'gray' fs solid 0.5 noborder
set xlabel 'x'; set ylabel 'y'
set key below
plot 'flow.dat' using 1:2:(2*$3):(2*$4) with vectors filled head lw 1.2 title 'velocity'
pd05
open SVG ↗

flow.dat holds x y u v, the potential flow past a unit cylinder.

Why it works ​

  • with vectors takes four columns: the tail x y and the components dx dy; (2*$3):(2*$4) scales them so the arrows read, in units of the axes.
  • set object circle draws the cylinder in axis units: it zooms and pans with the data in the HTML page.
  • set size ratio -1: a unit of x as long as one of y, so the directions are true.

Try this ​

  • using 1:2:3:4:(sqrt($3**2+$4**2)) with vectors lc palette: the arrows colored by the speed.
  • every 2 for a dense field: one arrow in two along each block.
  • set style arrow 1 head filled size 0.08,20 and with vectors arrowstyle 1: the head's size and angle.

Pitfalls ​

  • Arrows of a field that varies over decades are either invisible or overlapping: normalize them (($3/sqrt($3**2+$4**2))) and color them by the magnitude instead.
  • (2*$3):(2*$4) scales the arrows in axis units: a field on another scale needs another factor, or arrows that overlap their neighbours.

Reference: vectors. Next: D6. Voxels and isosurfaces.

foresight is available under your choice of license: GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT (License).