absolute
absolute

Reputation: 37

How to make a a arrow script in gnuplot from a series of grepped data from an text file

My data file is:

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

     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` 

and then want to draw the arrow from

 Xi, Yi to Xi, Yi nohead

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}'

and

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).

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

where variable is like this

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

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

X, Y, Z, .....

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

Upvotes: 0

Views: 155

Answers (1)

theozh
theozh

Reputation: 26068

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

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.

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

  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.

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.

Code: (modified after comments)

### 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

Result:

enter image description here

Upvotes: 1

Related Questions