1
votes

I have a c++ code that generates every time a variable number of ".txt" file. I am using a bash script that loads the txt files and send them to a gnuplot script. Then I have to plot in the same figure always the same 2 columns of each of them (representing a altitude vs time plot).

My problem is that the x coordinate (1st column of txt files) does not finish always at the same value and, when the last value of x coordinate is not zero,I need to insert a cross in the gnuplot plot. Do you have an idea about how to do it?

This is how I am plotting the multiple files

plot for [object in objectnames] object.".txt" using 1:2 w l title object

where "objectnames" is a string with all the filenames sent by the BASH

Now, for plotting the CROSSES, I thought about two ways:

  1. Send a array of coordinates to the gnuplot script and then set some label but GNUPLOT does not like arrays and I cannot create a variable number of label in this way.

  2. The alternative is to read somehow the txt file inside the gnuplot script but I have no idea how to do it.

Thanks for the help

EDIT

BASH SCRIPT

export DATA_DIR=${1:-/home/../output}
export objectname
space=" "
OUT_FILES="$(find -L $DATA_DIR -name '*_Trajectory.txt')"

for file in $OUT_FILES; do  
    fig=$(basename "$file")             
    objectID=$(echo $fig| cut -d'_' -f 1)

    # filenames concatenation
    objectname=$objectname$objectID$space
 done

 export figNameAltitude="${file/${fig}/altitudePlot.png}"

gnuplot -e "folder='${DATA_DIR}';objectnames='${objectname}';figName='${figNameAltitude}';lineWidth='${linewidth}'" altitudePlot.gp

GNUPLOT SCRIPT ( I avoid to insert all the lines regarding the title, axis and so on)

plot for [object in objectnames] folder.'/'.object."_Trajectory.txt" using 1:2 w l lw lineWidth title object
1
Please provide a minimal, complete example, including data and all plotting commands. - Mark Setchell
I insert some commands from bash and gnuplot script. I am aware that it is not something easy to explain just writing. My question can be summed up in a sentence: how can I add a symbol (a cross for example) at the end of the plot of a data set in gnuplot considering the fact that the script has to be the most generic as possible? - Ricc
I formatted the script as code; please check whether I go that right. - Peter - Reinstate Monica
where do you want to put that cross (which coordinate)? - PinkFloyd
Thanks Peter, it is right. The problem is that i do not know the coordinates a priori. I have this variable number of files and, if the first coloumn of each of them does not terminate at zero (as last value) I have to put a cross a the coordinate x= last value of first coloumn and y=last value of second coloumns. But this should happen only in some cases. Everything should be the most generic as possible - Ricc

1 Answers

0
votes

This might help

     set title "Energy vs. Time for Sample Data"

     set xlabel "Time"

     set ylabel "Energy"

     plot "d1.dat" with lines

     pause -1 "Hit Enter to continue" 

execute the script file as **$**gnuplot filename

click here for more details