Gnuplot &引用;“x范围无效”;将值用于$
我在linux上学习gnuplot。My data.tsv的外观如下所示:Gnuplot &引用;“x范围无效”;将值用于$,gnuplot,Gnuplot,我在linux上学习gnuplot。My data.tsv的外观如下所示: 1480420804 2016-11-29 04:00:04 -0800 foo1 $123.00 bar1 1480507205 2016-11-30 04:00:05 -0800 foo2 $124.25 bar2 1480593604 2016-12-01 04:00:04 -0800 foo3 $122.75 bar3 我使用第1列(从纪元开始的秒数)作为X,第4列(价格)作
1480420804 2016-11-29 04:00:04 -0800 foo1 $123.00 bar1
1480507205 2016-11-30 04:00:05 -0800 foo2 $124.25 bar2
1480593604 2016-12-01 04:00:04 -0800 foo3 $122.75 bar3
我使用第1列(从纪元开始的秒数)作为X,第4列(价格)作为Y
这是我的gnuplot脚本:
#!/usr/bin/gnuplot
set terminal png notransparent interlace size 640,480
set output "output.png"
set datafile separator tab
set xdata time
set timefmt "%s"
set format x "%4Y-%02m-%02d"
plot "data.tsv" using 1:4 title "Blah"
当我尝试运行此操作时,出现以下错误:
"./test.gp", line 9: warning: Skipping data file with no valid points
plot "data.tsv" using 1:4 title "Blah"
^
"./test.gp", line 9: x range is invalid
但是,如果我在data.tsv文件中删除第4列开头的所有美元符号,那么一切都正常
我的问题:有没有办法让gnuplot接受或跳过第4列价格中的“$”(这不是对你问题的回答,而是对你问题的回答,所以如果有人提出更好的建议,欢迎接受另一个答案)
只需在打印前对数据文件进行预处理,然后删除$
:
sed s/\$//g data.tsv >data2.tsv
我试着(或多或少地)按照@kebs的建议去做,但是失败了,当我在gnuplot中这样调用它时,出现了相同的“x range is invalid”错误消息:
plot "< sed s/\$//g data.tsv" using 1:4 title "Blah"
我改成这样说:
plot "< cat data.tsv | tr --delete '$'" using 1:4 title "Blah"
plot“
sed搜索命令的语法是s/
(模式)/
(替换)/
。sed命令s/\$//g
意味着搜索(s
)正则表达式\$
(一个转义的$
,一个字符),并将其替换为空字符串。结尾处的g
意味着“全局”这样做,而不仅仅是行中的第一次出现。
plot "< cat data.tsv | tr --delete '$'" using 1:4 title "Blah"