gpt4 book ai didi

plot - 使用 Gnuplot 每 n 个元素打印自定义标签

转载 作者:行者123 更新时间:2023-12-02 20:11:26 30 4
gpt4 key购买 nike

我想创建一个文件的散点图,如下所示:

counter  N   x  y   
1 200 50 50
2 200 46 46
3 200 56 56
4 200 36 36
5 200 56 56

这个文件有 240 行。 N 每 30 行递增 200。因此,当我绘制数字时,我想创建一个 x、y 值与计数器的散点图。这是我的代码:

plot "file" using 1:3 title "hb" with points pt 2 ps 1 lc rgb "red", \
"file" using 1:4 title "ls" with points pt 3 ps 1 lc rgb "blue"

因此,我的 x 轴范围为 [1,240]。

问题 是我希望 x 轴的标签包含第二列的值,并且我希望每 30 个点后打印一次。

因此,我希望将我的 x 轴标签自定义为:[200,400,600,800,1000,1200,1400,1600],它们之间各有 30 个点。

其实我之前也搜过这个问题,找到了解决方案并解决了。所以,我知道某处有答案。但显然我丢失了我的代码。我已经搜索旧帖子一个小时了,但找不到。

谁能帮我在这里使用自定义标签?

最佳答案

我不确定如何从 gnuplot 中的数据生成 xtics,所以我会使用 bash 为我生成它们:

#! /bin/bash
xtics='('$(cut -d' ' -f1,2 file | sort -nuk2 | sed 's/\(.*\) \(.*\)/\2 \1/;s/^/"/;s/ /" /;s/$/,\\/')$'\n)'
gnuplot <<EOF
set term png
set output '1.png'
set xtics $xtics
plot "file" using 1:3 title "hb" with points pt 2 ps 1 lc rgb "red", \
"" using 1:4 title "ls" with points pt 3 ps 1 lc rgb "blue"
EOF

在随机生成的输入上,它给出了这个输出:

generated graph

关于plot - 使用 Gnuplot 每 n 个元素打印自定义标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53543182/

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