scravy
scravy

Reputation: 12283

How to embed multiple datasets in a gnuplot command script for a single plot command?

I found out that in gnuplot one can obtain multiple curves / datasets from a single file:

splot "file.dat" using 1:2:3, splot "file.dat" using 1:4:5

Also one can embed data in a script like so:

splot "-" using 1:2:3
 1 0 1
 1 2 3
 0.5 3 1.5

However, the following seems not to work:

splot "-" using 1:2:3, "-" using 1:4:5
 1 0 1 4 4
 1 2 3 3 4
 0.5 3 1.5 2.5 -1

is this intentional, does a workaround exist or is it simply not possible?

Upvotes: 4

Views: 3179

Answers (3)

Gnuplot 5.0.1 datablocks

main.gnuplot

$data << EOD
 1 0.5  0.25  2  4
 2 1    1     4  8
 3 1.5  2.25  6 12
 4 2    4     8 16
 5 2.5  6.25 10 20
 6 3    9    12 24
 7 3.5 12.25 14 28
 8 4   16    16 32
 9 4.5 20.25 18 36
10 5   25    20 40
11 5.5 30.25 22 44
12 6   36    24 48
EOD

splot \
  "$data" using 1:2:3 with linespoints title "y = x/2, z = y^2", \
  "$data" using 1:4:5 with linespoints title "y = 2x,  z = 2*y"

Convert to PNG:

gnuplot -e 'set terminal png' -e 'set output "main.png"' main.gnuplot

Output:

enter image description here

Ubuntu 15.04 has the gnuplot5-x11 package.

On Ubuntu 14.04, you can compile gnuplot from source easily with:

cvs -d:pserver:[email protected]:/cvsroot/gnuplot login
cvs -z3 -d:pserver:[email protected]:/cvsroot/gnuplot co -P gnuplot
cd gnuplot
cvs update -r Release_5_0_1
sudo apt-get build-dep gnuplot
sudo apt-get install lua5.2
./prepare
./configure
time make
sudo make install
gnuplot --version

Yes, the project uses CVS at the time of writing!

Tested on Ubuntu 18.10, gnuplot 5.2.

Upvotes: 8

Dima Chubarov
Dima Chubarov

Reputation: 17159

The following script works with Gnuplot 4.4 as expected. The output attached below

set terminal png
set output 'e.png'
splot "-" using 1:2:3, "" using 1:2:3
 1 0 1 4 4
 1 2 3 3 4
 0.5 3 1.5 2.5 -1
e
 1 4 4
 1 3 4
 0.5 2.5 -1
e
set output

splot "-" using 1:2:3, "" using 1:2:3

Upvotes: 6

andyras
andyras

Reputation: 15910

The workaround would be

splot "-" using 1:2:3
 1 0 1
 1 2 3
 0.5 3

splot "-" using 1:2:3
 1 4 4
 1 3 4
 0.5 2.5 -1

If you can put the 5-column data into a plotscript, you can preprocess it to be two 3-column data sets in a plotscript.

I can't get it to work in one line as you have tried. It may not be possible, since

splot 'dat.txt' using 1:2:3, '' using 1:3:4

works, but

splot '-' using 1:2:3, '' using 1:4:5
 1 0 1 4 4
 1 2 3 3 4
 0.5 3 1.5 2.5 -1

does not.

Upvotes: 2

Related Questions