如何在gnuplot命令脚本中为单个绘图命令嵌入多个数据集?

时间:2012-05-01 12:39:56

标签: gnuplot

我发现在gnuplot中可以从单个文件中获取多个曲线/数据集:

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

还可以将数据嵌入到脚本中,如下所示:

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

但是,以下似乎不起作用:

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

是故意的,是否存在变通方法或者根本不可能?

3 个答案:

答案 0 :(得分:4)

以下脚本按预期使用Gnuplot 4.4。附录

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

答案 1 :(得分:4)

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"

转换为PNG:

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

输出:

enter image description here

Ubuntu 15.04有gnuplot5-x11个包。

在Ubuntu 14.04上,您可以使用:

轻松地从源代码编译gnuplot
cvs -d:pserver:anonymous@gnuplot.cvs.sourceforge.net:/cvsroot/gnuplot login
cvs -z3 -d:pserver:anonymous@gnuplot.cvs.sourceforge.net:/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

是的,该项目在撰写本文时使用CVS

在Ubuntu 18.10上测试,gnuplot 5.2。

答案 2 :(得分:1)

解决方法是

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

如果您可以将5列数据放入plotscript中,则可以将其预处理为plotscript中的两个3列数据集。

我不能像你尝试过的那样在一条线上工作。这可能是不可能的,因为

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

有效,但

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

没有。