在gnuplot中的两点之间绘制一条线 [英] Plotting a line between two points in gnuplot

查看:95
本文介绍了在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,ycoord1xcoord2,ycoord2绘制一条线.例如,在这种情况下,我将从0.1,0.20.4,0.3以及从0.5,0.30.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆