Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot stdin, how to plot two lines?

Tags:

gnuplot

I'm trying to produce a plot with two lines using data taken from stdin. I have a file "test.csv":

0,1.1,2 1,2,3 2,6,4 4,4.6,5 5,5,6 

I've been trying to plot this with commands like,

$ cat test | gnuplot -p -e "set datafile separator \",\"; plot '-' using 1:2 with lines, '' using 1:3 with lines;" 

But no matter what I try I get,

line 5: warning: Skipping data file with no valid points 

I assume this is because for the second line, stdin has already been exhausted. Is there a way to get gnuplot to take data from each column of stdin for different plots?

Thanks.

like image 923
Steve Avatar asked Jan 03 '11 15:01

Steve


People also ask

How use gnuplot to plot data from a file?

To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.

Does gnuplot support multiple Y axes on a single plot?

5.9 Does gnuplot support multiple y-axes on a single plot? Yes. 2D plots can have separate x axes at the bottom (x1) and top (x2), and separate y axes at the left (y1) and right (y2).

Does gnuplot have a GUI?

gnuplot is a command-line and GUI program that can generate two- and three-dimensional plots of functions, data, and data fits. The program runs on all major computers and operating systems (Linux, Unix, Microsoft Windows, macOS, FreeDOS, and many others).

What is gnuplot Splot?

splot is the command for drawing 3-d plots (well, actually projections on a 2-d surface, but you knew that). It can create a plot from functions or a data file in a manner very similar to the plot command. See plot for features common to the plot command; only differences are discussed in detail here.


1 Answers

The "-" is used to specify that the data follows the plot command. So if you use it, you'll need to do something like:

echo "set datafile separator \",\"; plot '-' using 1:2 with lines, '' using 1:3 with lines;" | cat - datafile.dat | gnuplot -p 

(Quoting above probably needs to be escaped).

What're you looking for is this:

plot '< cat -' 

Now, you can do:

cat test | sed ... | gnuplot -p "plot '< cat -' using ..." 

Note that you might need to feed in the input data via stdin multiple times if you're using options with plot, like so:

cat testfile testfile | gnuplot -p "plot '< cat -' using 1, '' using 2" 

In the above case, testfile must end with a line that has the sole character 'e' in it.

Manual reference

like image 113
PonyEars Avatar answered Sep 21 '22 16:09

PonyEars