How to use gnuplot to build a simple 2nd vector arrow?

This is my first time trying to use gnuplot, and I cannot find any instructions on how to do this. The closest I found is:

http://gnuplot.sourceforge.net/docs_4.2/node259.html

plot 'file.dat' using 1: 2: 3: 4 with vectors filled with lt 2 header

but I can not find any explanation about file.dat.

So can anyone give a simple example of how to draw a simple two-dimensional vector arrow? Thanks.

+4
source share
2 answers

gnuplot has very good help / documentation. Just type help plot or help vector to learn more about how to draw vectors in gnuplot.

The 2D vectors style draws a vector from (x, y) to (x + xdelta, y + ydelta).

A small arrow is drawn at the end of each vector.

4 columns: xy xdelta ydelta p>

This means that your input file must contain 4 columns, where the first two columns define the initial (x, y) position of the vector / arrow and its last two directions (x, y):

 # file.dat 0 0 .5 .5 0 1 -.5 .5 1 1 1 0 

Now enter the following command

 plot "file.dat" using 1:2:3:4 with vectors filled head lw 3 

gives the following result: Plotting vectors

Drawing vectors with the set arrow command

Consider using the set arrow command if you only need to draw a few vectors / arrows (for example, to highlight some points on the graph).

  set arrow 1 from pi/2,1 to pi/2,0 set arrow 2 from pi*3/2,-1 to pi*3/2,0 plot[0:2*pi] sin(x) 

set arrow example

+10
source

You can create 'file.dat' in a spreadsheet, save it as text and put in the gnuplot path using the cd to point gnuplot to its location. If this is not consistent with you, check out the examples using '+' and '++' and '-' in the gnuplot manual. This is a "virtual data file." Note that the first two are for one and two data points in the column, i.e. (x) or (x, y). You should use $1 and $2 as variables to calculate dx and dy. Be sure to set the xrange and yrange and isosamples for density for this.

Sort of....

 set isosamples 30 set samples 30 set xrange [-10:10] set yrange [-10:10] plot '++' using 1:2:(0.1*sin($1)):(0.1*cos($2)) with vectors 
+1
source

Source: https://habr.com/ru/post/1480684/


All Articles