2
votes

I have a program that generates data with a couple of input arguments and spits it out to stdout, I pipe this data to gnuplot and plot it (in my case I don't have an intermediate file):

$ cat sample_data.dat | gnuplot plot_script.gp

sample_data.dat:

0  0.5000    
1  0.9225    
2  0.2638    
3  0.7166    
4  0.7492    

plot_script.gp

#!/usr/bin/gnuplot
set terminal wxt size 700,524 enhanced font 'Verdana,10' persist

set style line 1 lc rgb '#0060ad' pt 7 lt 1 lw 0.5 # circle blue thin line
set style line 2 lc rgb '#949599' lt 1 lw 1 # --- grey

plot "<cat" using 1:2 w lp ls 1 notitle

what I want to accomplish is something like this

 plot "<cat" using 1:2 w l ls 2 notitle, \
      "" using 1:2 w p ls 1 notitle

That is, I want the line in one colour and the dots in another. I just can figure out a solution for this.

Could I read the stdin to a variable to store it so I could plot it twice?

There are some close questions on stackoverflow but nothing that I could really use to figure out to fit my problem, gnuplot-plot-two-data-set-from-stdin and pipe-plot-data-to-gnuplot-script

Edit:

I have now tried this as well:

plot for[col=2:3] "<awk '{print $1,$2,$2}'" using 1:col w lp ls col notitle
1

1 Answers

2
votes

You must duplicate your data before you send it to gnuplot. A way to to this on Unix-like systems is

$ cat sample_data.dat | cat - <(echo 'e') | tee - | gnuplot script.gp

and using the script which you already have, like

plot '<cat' w l, '' w p

In gnuplot 5 one could also use some trickery inside of gnuplot like

data = system('cat -')
set print $db
print data
unset print
plot $db w l, $db w p

and call this script just with

gnuplot plot_script.gp < sample_data.dat