-->

Plot points linked with edges using gnuplot

2019-09-08 15:33发布

问题:

I have a file of points (x, y) that I plot using gnuplot. If I have another file that shows which point is linked with which other point by an edge (e.g. (3.8, 6) linked to (4,7)), is it possible to visualise/plot this edges between points ?

回答1:

depending on how your data is organized, you may want to look into plotting with vectors. For example, if your datafile looks like:

#x1 y1 x2 y2
 1  1  3   3

You can plot this using:

set style arrow 1 nohead
plot "my_arrows.dat" using 1:2:($3-$1):($4-$2) with vectors arrowstyle 1

EDIT

Assuming all the points in your datafile are repeated, you can do the following:

set style arrow 1 nohead
plot "my_arrows.dat" using 1:2:($3-$1):($4-$2) with vectors arrowstyle 1,\
     "my_arrows.dat" using 1:2 w points

If they're not repeated, you can do:

set style arrow 1 nohead
plot "my_arrows.dat" using 1:2:($3-$1):($4-$2) with vectors arrowstyle 1,\
     "my_arrows.dat" using 1:2 w points ls 1 lc rgb "red" pt 1,\
     "my_arrows.dat" using 3:4 w points ls 1 lc rgb "red" pt 1

Note that you can play around with the linestyles (linecolor or lc, pointtype or pt, linewidth or lw etc. to make the points appear the same.)



回答2:

You might not be able to read the line positions in without using a separate utility to generate your plotscript, but the command to draw a line from point to point is

set arrow [X] from first x1,y1 to first x2,y2 nohead

where X is an optional tag number for the arrow, and (x1,y1) and (x2,y2) are points in the graph's coordinate system.



标签: gnuplot edge