1

As a follow up of: Gnuplot: Plotting several datasets with titles from one file, I have a test.dat file:

"p = 0.1"
1 1
3 3
4 1


"p = 0.2"
1 3
2 2
5 2

and I can plot it with no issues from within gnuplot using:

> plot for [IDX=0:1] 'test.dat' i IDX u 1:2 w lines title columnheader(1)

however I cannot pipe the data.

Here is the single line example:

$ cat test.dat | gnuplot --persist -e "plot for [IDX=0:1] '-' i IDX u 1:2 w lines title columnheader(1)"
line 10: warning: Skipping data file with no valid points

I get the warning message and only the first set is plotted. I tried to add an e at the end of the data file, but no luck... This should be trivial, am I making a silly mistake?


I've messing around a bit more. So these works:

gnuplot --persist -e "plot for [IDX=0:1] 'test.dat' i IDX u 1:2 w lines title columnheader(1)"
gnuplot --persist -e "plot for [IDX=0:1] '< cat test.dat' i IDX u 1:2 w lines title columnheader(1)"

These don't:

cat test.dat | gnuplot --persist -e "plot for [IDX=0:1] '-' i IDX u 1:2 w lines title columnheader(1)"
cat test.dat | gnuplot --persist -e "plot for [IDX=0:1] '< cat' i IDX u 1:2 w lines title columnheader(1)"

It looks like a bug to me. I tried few Gnuplot versions (4.6.6, 5.0.0, 5.0.3) but they all present the same behaviour.

Community
  • 1
  • 1
DarioP
  • 5,377
  • 1
  • 33
  • 52
  • Would it be suitable to use the gnuplot `<` filename keyword to getdata from pipe? And does it work that way? – bibi May 24 '16 at 15:28
  • @bibi not really, since I'm streaming the data from another process, but yes `plot '< cat test.dat'` works... what a weird issue! I should be able to solve pretty easily going through the disk, but the pipe *should* work as well. – DarioP May 24 '16 at 15:33
  • I still can't figure out why not run your command from within gnuplot – bibi May 25 '16 at 06:46
  • @bibi that's because I wanted to ship a single Python script. Doing as you suggests forces me to ship a Python and a Gnuplot script and the user needs to launch the latter, which may be confusing as it breaks my previous standard. – DarioP May 25 '16 at 07:08

1 Answers1

2

Ok, I've finally got it browsing the documentation. When piping, each index selection requires to repeat the whole data:

plot '-' index 0, '-' index 1
2
4
6


10
12
14
e
2
4
6


10
12
14
e

or, as a much simpler alternative, one can just do:

plot '-', '-'
2
4
6
e
10
12
14
e
DarioP
  • 5,377
  • 1
  • 33
  • 52