Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gnuplot

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?

like image 390
scravy Avatar asked Dec 06 '22 15:12

scravy


1 Answers

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.