5

I am new to gnuplot and I am troubled in passing my argument alot, now I have this simple bash script and a gnuplot script.

in the bash script plot.sh I should modify my file then send it to the gnuplot script to be plotted OR I can modify my file and just send a parameter (a number passed from another script $1) to the gnuplot script which identifies which file to be plotted, the problem is neither of the two ways is working, I don't seem to get it right! any help?

here's my bash script plot.sh

#!/bin/bash

sed -i 's/ns/;/g' /dev/shm/waitingTime$1.txt
gnuplot -e "filename='/dev/shm/waitingTime$1'" file.gnuplot

And here is my gnuplot script called file.gnuplot

#!/home/yas/file.gnuplot

set xlabel "start"    
set ylabel "Delay"
set autoscale
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot<"filename"> using 1:2 w points title "tests"
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set output '/dev/shm/TT.pdf'
pause -1

end of file.gnuplot

1
  • Move your "set terminal" and "set output" to before the "plot" line. I am not an expert at gnuplot, but in the scripts I use, that is the order of things. There may be other issues, I don't know. Jun 15, 2015 at 13:43

1 Answer 1

2

If I understand correctly, you want the graph to show up on the display and then have a copy in the PDF file /dev/shm/TT.pdf.

I see two problems here:

  1. The instruction for the plot --- you store the file name in filename, so ypu should just say

    plot filename  using 1:2 w points title "tests"
    

    without the <"... things.

  2. If you want the pdf file you should add a replot after the change of terminal and output file (double check you can write in the destination directory).

I have created a file data.dat and the file file.gnuplot:

set xlabel "start"    
set ylabel "Delay"
set autoscale
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot filename   using 1:2 w points title "tests"
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set output 'TT.pdf'
replot
pause -1

And calling it with:

gnuplot -e "filename='data.dat'" file.gnuplot 

I have the output:

enter image description here

...and the corresponding TT.pdf file.

By the way, instead of the pause at the end, I find much better to add

set terminal wxt persist 

at the start, and remove the pause. The script will finish naturally and the window with the graph will stay put until you dismiss it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.