gpt4 book ai didi

gnuplot - gnuplot 中同一数据文件中的多个数据集

转载 作者:行者123 更新时间:2023-12-05 01:38:08 28 4
gpt4 key购买 nike

我有以下类型的文件:

<string1> <x1> <y1>
<string2> <x2> <y2>
...

我想从 (x,y) 值绘制一个散点图,在不同数据集中的第一列中有不同的字符串,这些字符串将用不同的颜色绘制(我有许多不同的 x,y 值但只有几个不同的字符串)。我试过这个:

plot "DATAFILE" using 2:3 title column(1)

不幸的是,这个选择了第一行的第一列并将其用作所有条目的标题。

最佳答案

您可以使用 awk 只选择第一列与您的字符串匹配的行:

plot "<awk '$1~/string1/' DATAFILE" using 2:3 title column(1),\
"<awk '$1~/string2/' DATAFILE" using 2:3 title column(1)

等等。对于内置的 gnuplot 解决方案,您可以:

plot "DATAFILE" u 2:(stringcolumn(1) eq "string1" ? $3:1/0),\
"DATAFILE" u 2:(stringcolumn(1) eq "string2" ? $3:1/0)

如果你想做一些更自动化的事情来为第 1 列中的每个唯一条目生成图表,这个解决方案对我有用:

输入文件(test.dat - 分开,否则需要更改下面的cut语句):

one 1   3
two 2 4
ten 3 5
ten 4 3
two 5 4
one 6 5
one 7 3
ten 8 4
two 9 5
ten 10 3
two 11 4
one 12 5

以下行为 gnuplot 创建绘图语句,并保存在文件中:

cut -f1 test.dat | sort -u | awk '
BEGIN {print "plot\\"}
{print "\"test.dat\" u 2:(stringcolumn(1) eq \""$1"\" ?\$3:1/0),\\"}' > plot.gp

内容是:

plot\
"test.dat" u 2:(stringcolumn(1) eq "one" ?$3:1/0),\
"test.dat" u 2:(stringcolumn(1) eq "ten" ?$3:1/0),\
"test.dat" u 2:(stringcolumn(1) eq "two" ?$3:1/0),\

然后你会做:

gnuplot plot.gp

或将行 load "plot.gp" 添加到您的脚本中。

我很确定一定有一个“仅限 gnuplot”的解决方案,但这超出了我的知识范围。希望这会有所帮助。

关于gnuplot - gnuplot 中同一数据文件中的多个数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38654991/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com