4

I want to create a streamline like arrow lines in Gnuplot,I already have the data points that I needed, so I think my problem is not the same as this post says and different from this post because I have already obtain the data needed for stramlines.

What I have done is like this:

have done

So the red lines are vectors show flow field and green line is streamlines to guide the readers the direction of the flux. And all the large blue arrows are my aim to be plotted in GNUPLOT. I have kown how to plot middle arrows as this post has shown but what code I need to do if I want to plot more arrows along the lines?

To be more detailed, How can I plot like this:

aim

I supply my data file here :

velocity.txt is for vector flow field data as "index,X,Y,vx,vy,particle-numbers"

line.txt is for streamline data as "X,Y"

and My gnu file is bleow:

set terminal postscript eps size 108,16 enhanced font "Arial-Bold,100"
set output 'vector.eps'

unset key
set tics
set colorbox
set border 0
set xtics 2
#set xlabel 'x'
#set ylabel 'y'


set xrange [0:108]
set yrange [0:16]
#set cbrange [0:40]

set nolabel
set style line 4 lt 2 lc rgb "green" lw 2

plot 'velcoity.txt' u 2:3:(250*$4):(250*$5) with vectors lc 1,'line.txt' u 1:2 ls 4

Thank you!

Community
  • 1
  • 1
sikisis
  • 458
  • 9
  • 21
  • can someone please share the velocity.txt & line.txt files. When I click to download it says access forbidden. – Pal Jan 16 '19 at 16:25

1 Answers1

5

To plot arrows along a line you can again use the vectors plotting style like you do already for the stream field.

But to get a proper plot you must consider several points:

  1. Usually gnuplot limits the size of the arrow heads to a fraction of the arrow length. So, if you want to plot a continuous line with arrows heads, the arrows themselves should have a very short length. To avoid downscaling of the arrow heads, use the size ... fixed option, which is available only since version 5.0

  2. You have only the trajectory, x and y values, of the line. To extract the arrow direction, the simplest approach would be to use the difference between two neighbouring points (or at a distance of two or three points).

  3. You can extract these differences in the using statement. As pseudo code, one could do the following:

    if rownumber modulo 10 == 0:
        save x and y values
    else if rownumber modulo 10 == 1:
        draw arrow from previous point to current point, only with a head
    else 
        ignore the point.
    

    Putting this pseudo-code in the using statement gives the following:

    ev = 10
    avg = 1
    sc = 0.1
    plot 'line.txt' u (prev_x = (int($0)%ev == 0 ? $1 : prev_x), prev_y = (int($0)%ev == 0 ? $2 : prev_y), int($0)%ev == avg ? $1 : 1/0):2:(sc*(prev_x-$1)):(sc*(prev_y-$2)) w vectors backhead size 2,20,90 fixed ls 4
    

    To make things more flexible, I introduced some variables: ev tells you the difference count between two arrows heads, avg the distance between two points used to calculate the arrow direction, and sc the length of the arrow shaft.

As further improvement you can use the length of the stream field arrows to colour the stream field vectors. This gives the following script

reset
unset key
set tics
set colorbox
set border 0
set xtics 2

set autoscale xfix
set autoscale yfix
set autoscale cbfix
set style line 4 lt 2 lc rgb "green" lw 2
ev=30
avg=3
sc=0.1
field_scale=500
plot 'velcoity.txt' u 2:3:(field_scale*$4):(field_scale*$5):(sqrt($4**2+$5**2)) with vectors size 1,15,45 noborder lc palette,\
     'line.txt' u 1:2 ls 4 w l,\
     '' u (prev_x = (int($0)%ev == 0 ? $1 : prev_x), prev_y = (int($0)%ev == 0 ? $2 : prev_y), int($0)%ev == avg ? $1 : 1/0):2:(sc*(prev_x-$1)):(sc*(prev_y-$2)) w vectors backhead size 2,20,90 fixed ls 4

With the result (qt terminal):

enter image description here

Christoph
  • 47,569
  • 8
  • 87
  • 187