4

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?

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Could you explain the first line: '$data << EOD'. Why do you start with a EOD? I cound't find this in the docs.
@JorisKinable just a magic syntax to inline the data that would otherwise be in a file. Syntax taken from shell heredocs. See also help datablock inside gnuplot 5.0.1.
6

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

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.