Search code examples
vectorplotgnuplotnumerical-methods

gnuplot vector arrow length and streamlines


I have already asked about vector fields in here. Now I want to know a bit more about it.

How can I make it so that each arrow has the same fixed length and define the magnitude of the value by color?

And is it still not possible to plot streamlines in gnuplot? If possible, how can I do that?

For now I have this and need to upgrade it.

set term pngcairo
set title 'Navier-Stokes Equation'
set terminal png size 1280,720
set output 'vec.png'
plot 'vec' u 1:2:($3/$5):($4/$5) w vec t 'Vector Field'

enter image description here

UPDATE

Thanks to @theozh I've got what I wanted. I want to share my result as it could be useful for someone else. Now I use these instructions to plot my vector field.

reset session
set size square
set palette rgb 33, 15, 10
set term pngcairo
set title 'Navier-Stokes Equation'
set terminal png size 1280, 720
set output 'vec.png'
plot 'vec.dat' u 1:2:(0.08*$3):(0.08*$4):(sqrt($3**2+$4**2)) w vec lw 2 lc palette notitle

enter image description here


Solution

  • About the same length: simply normalize your vectors.

    About the color: you can add a "column" and the end. The last column will define the color according to a palette.

    I don't know about streamlines (what exactly they are and how to possibly realize them).

    With the example script:

    Script: (Edit: define function for length L() to make plot command shorter and clearer.)

    ### plot with normalized/scaled vectors
    reset session
    
    set size square
    set samples 25
    set palette rgb 33,13,10
    set key noautotitle
    
    Scale        = 0.5
    L(colX,colY) = sqrt(column(colX)**2+column(colY)**2)
    
    plot [-5:5] '++' u 1:2:(Scale*$1/L(1,2)):(Scale*$2/L(1,2)):(L(1,2)) w vec lc palette
    ### end of script
    

    enter image description here