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

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

本文介绍了如何使用文本文件中的一系列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

========

我要设置电话号码

========

I want to set the number

`-42.3732 and 666.3634 as y-axis limit`

然后要从

 Xi, Yi to Xi, Yi nohead

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

where Xi is a variable number and depends on the data file but I can grep it using

 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的每个点上绘制箭头.

I want to draw arrows on each of these point from Xi, Yi to Xi, Yf in my gnu script.

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

I have some idea that it can be done if we store the above data in a variable form and the do like this

set VARIABLE

其中的变量是这样的

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

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

and for the next part I want to label each Xi at x-axis with some letter say

X, Y, Z, .....

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

Could you please advise me how I can manage it in gnuplot?

推荐答案

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

It is still not clear to me from your description where to get which values.

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

My understanding is the following:You have one (or several?) files which have the structure which you gave (whereas the structure of the second line with > and the data after this looks strange to me).As I understand, the awk-command extracts the value of the last token (column) in a line.So, I assume xi is the last value of each line. In line 2, xi would be in column 14 and in all the following lines xi would be in column 8.

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

A procedure in gnuplot (without awk) would be the following:

  1. 将文件绘制到虚拟表中.如果行号为1(即($0==1)),则将第2列$2和第3列$3中的值分别分配给YminYmax.始终将列值8 $8分配给Xmax,因此在绘制Xmax之后将包含最后一个值,此处为5.4063.
  2. 然后绘制文件with vectors(跳过第一行),并在下一行使用第14列,在其他所有行上使用第8列作为xi值.
  1. plot the file into a dummy table. If line number is 1 (i.e. ($0==1)) assign the values in column 2 $2 and column 3 $3 to Ymin and Ymax, respectively. Always, assign column value 8 $8 to Xmax, so after plotting Xmax will contain the last value, here 5.4063.
  2. then plot the file with vectors (skipping the first line) and use column 14 for the next line and column 8 for all the other lines as xi value.

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

After your comment this is probably more what you want.You can get details from gnuplot help when typing help <keyword>, e.g. 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

结果:

这篇关于如何使用文本文件中的一系列grepped数据在gnuplot中制作箭头脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 09:38