2

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

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer. I don't have access to gnuplot 5 so can't try it. But I have some issues running the code you provided. The output does not seem to be deterministic. I get different sorting of the doubled data points randomly, and when I manually copy to the right structure I get the error warning: Skipping data file with no valid points
0

As old as this thread is, I found the information useful in solving my own problem. For what it's worth, I expect gnuplot 5 to be accessible on most systems now. Here's a script I wrote with it:

#!/usr/bin/gnuplot -c
set term x11 persist  # Allow script to exit without closing plot-window.
set xlabel ARG1       # Axis labels passed-in as parameters.
set ylabel ARG2
plot "/dev/stdin" with points              # Read points from input-pipe.

I can just pipe-in two columns of data and generate the chart:

cat POINTS | plot.points "X-axis label" "Y-axis label"

Comments

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.