我想绘制JCAMP-DX格式的频谱。 它在一行中有多个y轴记录,为x轴指定了增量。
简单示例:线性图(1,1)到(12,12)
1 1 2 3
4 4 5 6
7 7 8 9
10 10 11 12
第一列表示x轴,第二列表示y轴,每个随后的属于x的y数据加1。我可以用命令绘制它:
plot "test.gnuplot" using 1:2 linecolor "black" with dots, "test.gnuplot" using ($1+1):3 linecolor "black" with dots, "test.gnuplot" using ($1+2):4 linecolor "black" with dots
然而,光谱要复杂得多,我想用线条绘制它,这是不可能的,使用上述方法(线条不会连接,并会在绘图的非线性区域产生丑陋的交叉点。)
现在我只绘制第二列(using 1:2
),但这会降低分辨率
我想避免使用外部过滤器(awk等)和编辑输入文件(vim等)。
实际数据(跳过前35行 - 数据规范):http://webbook.nist.gov/cgi/cbook.cgi?JCAMP=C7664417&Index=1&Type=IR
答案 0 :(得分:0)
您想避免使用外部工具,但是可以创建一个带有gnuplot的临时文件吗?
我从webbook.nist.gov获取了实际数据,并删除了注释行和y值小于其他行的最后一个数据行。
这是我的建议:
datafile = "7664-41-7-IR.jdx2"
dx = 0.935253
col_count=6
# Build a function that will create a new datafile by converting
# single lines of the form "x y1 y2 y3 ..." into multiple
# lines of the form "x y1", "x+dx y2", "x+2*dx y3", ...
#
# We will call this function later for each input line and append
# the new data values.
all_command = "all = sprintf(\"%s"
do for [i=2:col_count] {
all_command = all_command."%f %f\n"
}
all_command = all_command."\", all"
do for [t=2:col_count] {
all_command = all_command.", column(1)+dx*(".t."-2), column(".t.")"
}
all_command = all_command.")"
# Just to check:
print all_command
# Now we call the function for each input line. The variable "all" will contain
# the "expanded" data. Note, the "plot" command is a dummy plot.
all = ""
plot datafile using 1:( @all_command, 1)
# Generate the temporary data file
set print "temp_file.dat"
print all
plot datafile w p, "temp_file.dat" w l
这是输出的一部分:
要统计行数,请检查this question。