在gnuplot中的两点之间绘制一条线 [英] Plotting a line between two points in gnuplot
问题描述
我有一个csv文件,该文件具有以下格式,具有四列(作为MWE
):
I have a csv file with a following format having four columns (as a MWE
):
xcoord1,ycoord1,xcoord2,ycoord2
0.1,0.2,0.4,0.3
0.5,0.3,0.7,0.5
我想使用gnuplot从每个xcoord1,ycoord1
到xcoord2,ycoord2
绘制一条线.例如,在这种情况下,我将从0.1,0.2
到0.4,0.3
以及从0.5,0.3
到0.7,0.5
画两条线.
I want to plot a line from each xcoord1,ycoord1
to xcoord2,ycoord2
using gnuplot. For example in this case, I would draw two lines from 0.1,0.2
to 0.4,0.3
and 0.5,0.3
to 0.7,0.5
.
怎么可能?
推荐答案
一种解决方案是预处理文件并生成Gnuplot脚本,该脚本将使用set arrow
命令.另一种方法是,只需进行一点预处理就可以直接绘制输入文件.诀窍是将数据文件中的每一行转换为一个单独的块,例如
one solution would be to preprocess your file and generate a Gnuplot script which would employ the set arrow
command. Alternatively one can plot the input file directly with a little preprocessing. The trick is to convert each line in the data file into a separate block, e.g.,
xcoord1,ycoord1,xcoord2,ycoord2
0.1,0.2,0.4,0.3
0.5,0.3,0.7,0.5
将被转换为
0.1 0.2
0.4 0.3
0.5 0.3
0.7 0.5
然后,Gnuplot将仅连接一个块内的点.为此,您可以执行以下操作:
Gnuplot will then connect only points within one block. To achieve this, you could do:
plotCmd(fname)=sprintf("<gawk -F, 'NR>1{printf \"%%s\\t%%s\\n%%s\\t%%s\\n\\n\",$1,$2,$3,$4}' %s", fname)
plot plotCmd('input.csv') w lp
这篇关于在gnuplot中的两点之间绘制一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!