我正在尝试绘制两列数据(日期、重量),一般来说它是有效的。我的问题是,我必须用空格分隔列,尽管我更喜欢使用逗号。
数据文件示例(2014 年 7 月 24 日体重为 85.73 公斤):
"2014-07-24 06:02:42",85.73
这是我当前的绘图脚本(插入行号以便于引用):
1 set grid
2 set datafile separator ","
3 set ylabel 'Weight (kg)'
4 set xdata time
5 set timefmt '"%Y-%m-%d %H:%M:%S"'
6 set xrange ['"2014-01-01 00:01"':'"2019-08-01 00:01"']
7 set style data lines
8 plot "weight" using 1:2
我可以将第 2 行中的分隔符设置为我喜欢的任何值,但它不起作用。尽管 gnuplot 更改了分隔符,但我会收到以下错误(gnuplot> 如何数据文件分隔符
报告数据文件字段由任意 1 个字符“,”分隔
)
$ gnuplot weight.plot
"weight.plot", line 8: warning: Skipping data file with no valid points
plot "weight" using 1:2
^
"weight.plot", line 8: all points y value undefined!
我在 Linux Mint 上使用 gnuplot 5.2 patchlevel 2
知道我做错了什么吗?
最佳答案
当 gnuplot 从 cvs 文件中读取时,它会删除任何可能多余地分隔每个字段的双引号。我记得这样做是为了与 MSExcel 保持一致,MSExcel 不区分 123 和“123”。因此,当程序尝试应用 timefmt
时,引号已被删除,并且格式不匹配。如果您只需从 set timefmt
和 set xrange
中删除多余的双引号即可:
set grid
set datafile separator ","
set ylabel 'Weight (kg)'
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set xrange ["2014-01-01 00:01":"2019-08-01 00:01"]
set style data lines
set table # for debugging
plot "weight" using 1:2
# Curve 0 of 1, 1 points
# Curve title: ""weight" using 1:2"
# x y type
"2014-07-24 06:02:42" 85.73 i
关于linux - gnuplot "datafile separator"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57242266/