如何使用文本文件中的一系列grepped数据在gnuplot中制作箭头脚本

时间:2019-10-11 08:03:32

标签: gnuplot

我的数据文件是:

============

     This is your required output
Range:  -42.3732  666.3634eV  Yi, Yf > DATA-point FIX:  0.0000 0.0000 0.0000   x LIST   0.0000
DATA-point FIX:  0.5000 0.0000 0.0000   x LIST   0.5000
DATA-point FIX:  0.7500 0.3750 0.2641   x LIST   1.0224
DATA-point FIX:  0.0000 0.0000 0.0000   x LIST   1.9015
DATA-point FIX:  0.3750 0.3750 0.5282   x LIST   2.6500
DATA-point FIX:  0.5000 0.5000 0.3522   x LIST   2.8995
DATA-point FIX:  0.0000 0.0000 0.0000   x LIST   3.6895
DATA-point FIX:  0.5000 0.0000 0.3522   x LIST   4.3010
DATA-point FIX:  0.6250 0.2500 0.4402   x LIST   4.5941
DATA-point FIX:  0.7500 0.2500 0.3522   x LIST   4.7470
DATA-point FIX:  0.5000 0.5000 0.3522   x LIST   5.1005
DATA-point FIX:  0.5000 0.2500 0.5282   x LIST   5.4063

done junk has written below this part

========

我要设置电话号码

`-42.3732 and 666.3634 as y-axis limit` 

然后要从

绘制箭头
 Xi, Yi to Xi, Yi nohead

其中Xi是一个可变数字,取决于数据文件,但我可以使用

 grep LIST data.dat |  awk '{print $NF}'

Yi and Yf are the y-axis limit as mentioned above but changes according to data file so these numbers are not the one that I mention here).

我想在我的gnu脚本中在从Xi,Yi到Xi,Yf的每个点上绘制箭头。

我有一个想法,如果我们将上述数据以可变形式存储,并且这样做是可以做到的

set VARIABLE

变量是这样的

VARIABLE=`arrow from Xi,Yi to Xi,Yf nohead ; set`

在下一部分中,我想在x轴的每个Xi上标注一些字母

X, Y, Z, .....

您能告诉我如何在gnuplot中对其进行管理吗?

1 个答案:

答案 0 :(得分:1)

根据您的描述,我仍然不清楚从何处获取哪些值。

我的理解如下: 您有一个(或几个?)文件,这些文件具有您给定的结构(而第二行带有>的结构以及此后的数据对我来说似乎很奇怪)。 据我了解,awk命令提取一行中最后一个标记(列)的值。 因此,我假设xi是每行的最后一个值。在第2行中,xi在第14列中,在随后的所有行中,xi在第8列中。

gnuplot中的过程(不带awk)如下:

  1. 将文件绘制到虚拟表中。如果行号为1(即($0==1)),则将第2列$2和第3列$3中的值分别分配给YminYmax。始终将列值8 $8分配给Xmax,因此在绘制Xmax之后将包含最后一个值,此处为5.4063。
  2. 然后绘制文件with vectors(跳过第一行),并在下一行使用第14列,在其他所有行上使用第8列作为xi值。

发表评论后,这可能更是您想要的。 您可以在输入help <keyword>时从gnuplot帮助中获取详细信息,例如help vectors

代码:(注释后已修改)

### Extract values from file
reset session

FILE = 'tbExtractArrow.dat'

# extract Ymin, Ymax and Xmax
set table $Dummy
    plot FILE u ($0==1?(Ymin=$2,Ymax=$3):NaN,Xmax=$8) w table
unset table
print Ymin,Ymax,Xmax

# define formula for column to extract xi
myColumn(n) = n==0 ? 14 : 8

set xrange [0:Xmax]
set yrange[Ymin:Ymax]
set xtics ( "{/Symbol G}" 0.00000, "{/Times-New, F}" 0.27445, "{/Times-New Q}" 0.46775, "{/Times-New, Z}" 0.74220, "{/Symbol G}" 0.93550, "etc." 1.4) 

plot FILE skip 1 u (column(myColumn($0))):(Ymin):(0):(Ymax-Ymin) w vectors nohead lw 2 lc rgb "red" notitle
### end of code

结果:

enter image description here