首页 > 解决方案 > 如何从文本文件中的一系列 grepped 数据在 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

 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中管理它吗?

标签: gnuplot

解决方案


从您的描述中我仍然不清楚从哪里获得哪些值。

我的理解如下:您有一个(或几个?)文件具有您提供的结构(而第二行的结构>和之后的数据对我来说看起来很奇怪)。据我了解,awk 命令提取一行中最后一个标记(列)的值。所以,我假设xi是每行的最后一个值。在第 2 行中,xi将在第 14 列中,在以下所有行xi中,将在第 8 列中。

gnuplot(没有 awk)中的过程如下:

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

在您发表评论后,这可能是您想要的更多。您可以在键入时从 gnuplot 帮助中获取详细信息help <keyword>,例如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

结果:

在此处输入图像描述


推荐阅读