Reputation: 335
I would like to pipe data into gnuplot and plot it without entering the gnuplot command line or providing an existing script file. Eg a one-liner such as cat datafile | gnuplot
and see the plot come up. Suppose the datafile is well formatted, such as two simple columns of numerical data separated by a tab or space.
As is this would close immediately even if it would work (which it doesn't) but this can be resolved with the -persist option (abbreviated -p).
Essentially I would like the following line of code to work, or to understand why it doesn't and how to modify it to work: echo -e "1 3\n2 4\n3 5" | gnuplot -p <<< "plot '-'"
I can get something working using the -e option, but this seems to often break for me once I start making more complex plotting commands and I don't understand exactly what that option is doing, so I would prefer to simply write a short script file using a heredoc, as attempted above. This works: echo -e "1 3\n2 4\n3 5" | gnuplot -p -e "plot '-'"
Why doesn't the column data that is piped into gnuplot simply plot, even when using the plot '-'
syntax to request that plot take the data in from stdin?
Upvotes: 3
Views: 4080
Reputation: 2342
You want to pipe 2 different streams to gnuplot
: data and plot commands. Gnuplot takes just one. Then why not simply concatenate the plot commands and data?
cat > file << .
plot '-' using (\$1):(\$2)
1 2
2 3
3 4
e
.
and then cat file | gnuplot -p
.
Remember to escape the $
characters if they are gnuplot variables and not shell variables.
Upvotes: 0