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

4
我发现在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个回答

8

Gnuplot 5.0.1 数据块

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

输出:

在此输入图像描述

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。


你能解释一下第一行代码:'$data << EOD'吗?为什么要以EOD开头?我在文档中找不到这个。 - Joris Kinable
@JorisKinable 只是一种神奇的语法,可以将本应在文件中的数据内联。该语法取自shell heredocs。请参阅gnuplot 5.0.1中的help datablock - Ciro Santilli OurBigBook.com

6
以下脚本与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


2
解决方法是:
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列数据放入一个绘图脚本中,那么您可以在绘图脚本中预处理它,使其成为两个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

不会。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接