从 gnuplot 中的数据文件中选择一行
Selecting a single row from a data file in gnuplot
我有一个包含 100 列和数千行的数据文件,但我希望能够 select 一行,并在该行中使用偶数列作为 X- 的输入轴和奇数列作为绘图 Y 轴的输入。有什么办法可以在 gnuplot 中做到这一点吗?
所以这里是我完成的脚本,用于绘制给定数据文件中的给定行,其中奇数列作为 x 轴,偶数列作为 y 轴。
#!/usr/bin/gnuplot
set term pdf
set output "plot.pdf"
line_number=1
data_file="data.dat"
set xrange[0:10]
set yrange[0:10]
table_file="/tmp/gnuplot_tab.dat"
set table table_file
plot for[i=1:*:2] "<(sed -n '".line_number."p' ".data_file.")" u i:i+1
unset table
unset key
plot table_file
让我们解释一下这个脚本:
首先我们用line_number
指定行号,用data_file
指定数据文件名。 set table table_file
的效果是,如 gnuplot documentation 所指定,在文件 ̀table_fileinstead of ploting them with
plot` 命令中打印点坐标。
每个 i
的 plot for[i=1:*:2]
图从 1
开始,当没有更多列可以绘制时结束,并在每次迭代中递增 2
。这个想法是将列 i
(即奇数)和i+1
(即偶数)作为坐标(或使用逆 i+1:i
为 x 轴取偶数,为 y 轴取奇数)。
"<(sed -n '".line_number."p' ".data_file.")"
部分灵感来自Gnuplot plotting data from a file up to some row,选择你指定的行作为文件。由于 set table
已经完成,此 plot
命令将每个坐标保存到一个新文件中。这是在两列文件中转换行的技巧。
最后脚本禁用了̀set tableto then plot the saved file
table_file`
我使用以下数据文件对其进行了测试,将行号从 1
更改为 2
:
10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
0 10 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 10 0
我有一个包含 100 列和数千行的数据文件,但我希望能够 select 一行,并在该行中使用偶数列作为 X- 的输入轴和奇数列作为绘图 Y 轴的输入。有什么办法可以在 gnuplot 中做到这一点吗?
所以这里是我完成的脚本,用于绘制给定数据文件中的给定行,其中奇数列作为 x 轴,偶数列作为 y 轴。
#!/usr/bin/gnuplot
set term pdf
set output "plot.pdf"
line_number=1
data_file="data.dat"
set xrange[0:10]
set yrange[0:10]
table_file="/tmp/gnuplot_tab.dat"
set table table_file
plot for[i=1:*:2] "<(sed -n '".line_number."p' ".data_file.")" u i:i+1
unset table
unset key
plot table_file
让我们解释一下这个脚本:
首先我们用line_number
指定行号,用data_file
指定数据文件名。 set table table_file
的效果是,如 gnuplot documentation 所指定,在文件 ̀table_fileinstead of ploting them with
plot` 命令中打印点坐标。
每个 i
的 plot for[i=1:*:2]
图从 1
开始,当没有更多列可以绘制时结束,并在每次迭代中递增 2
。这个想法是将列 i
(即奇数)和i+1
(即偶数)作为坐标(或使用逆 i+1:i
为 x 轴取偶数,为 y 轴取奇数)。
"<(sed -n '".line_number."p' ".data_file.")"
部分灵感来自Gnuplot plotting data from a file up to some row,选择你指定的行作为文件。由于 set table
已经完成,此 plot
命令将每个坐标保存到一个新文件中。这是在两列文件中转换行的技巧。
最后脚本禁用了̀set tableto then plot the saved file
table_file`
我使用以下数据文件对其进行了测试,将行号从 1
更改为 2
:
10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0
0 10 1 9 2 8 3 7 4 6 5 5 6 4 7 3 8 2 9 1 10 0