Plot points linked with edges using gnuplot

倖福魔咒の 提交于 2019-12-11 15:04:13

问题


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.



来源:https://stackoverflow.com/questions/11104378/plot-points-linked-with-edges-using-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!