0

I have a txt file with trajectories. How can I plot the column 3 by gnuplot and have vertical line to separate trajectories.

#indexes:         0
   1        -0.375E+04         0.382E+01        
   2        -0.375E+04         0.332E+01        
   3        -0.376E+04         0.353E+01        
#indexes:        1
   1        -0.735E+04         0.093E+01
   2        -0.735E+04         0.096E+01
   3        -0.735E+04         0.082E+01
   4        -0.735E+04         0.094E+01
#indexes:         2
   1        -0.835E+04         0.401E+01
   2        -0.035E+04         0.438E+01
   3        -0.365E+04         0.438E+01 

I have many indexes.

Photo:

enter image description here

1 Answer 1

1

Here's an example shell script that works with your example data. It assumes the data is in a file data, creates a 2nd tmp file /tmp/data2, and an image /tmp/data.png.

#!/bin/bash
max=$(awk <data '
 !/^#indexes/{ if($3+0>max)max = $3 }
 END {print max}')

awk <data >/tmp/data2 -vmax="$max" '
  /^#indexes/ {printf "%s %s\n",i,max; next}
              { i++; }'

gnuplot <<\!
set terminal png
set output "/tmp/data.png"
plot "data" using 3 with lines linetype rgb "red",\
 "/tmp/data2" using 1:2 with impulse linetype rgb "blue"
!
# eg: display /tmp/data.png

The first awk finds the max value of the 3rd field. The 2nd awk creates a data line "i max" for each "#indexes" line, where i counts the number of data lines, i.e. the x axis values for the blue vertical lines.

Sign up to request clarification or add additional context in comments.

1 Comment

Very neat that you did the parsing in bash

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.