我在C -code中使用Gnuplot_i库(版本2.11),它生成了一些png -pictures。但是时间/日期列无法正确格式化。
来源:
gnuplot_ctrl * h0 ;
h0 = gnuplot_init() ;
gnuplot_set_xlabel(h0, "Header") ;
gnuplot_cmd(h0, "set terminal png size 800,480") ;
gnuplot_cmd(h0, "set output 'picture.png'") ;
gnuplot_cmd(h0, "set xdata time") ;
gnuplot_cmd(h0, "set timefmt '%Y-%m-%d-%H:%M'") ;
gnuplot_cmd(h0, "set format x '%H:%M' ") ;
gnuplot_cmd(h0, "set grid") ;
gnuplot_cmd(h0, "plot \"datafile.tsv\" u 1:2 w l t \"Title\" ");
gnuplot_close(h0) ;
datafile.tsv包含:
2017-09-08-18:03 12.69
2017-09-08-18:04 12.69
2017-09-08-18:05 12.69
2017-09-08-18:06 12.69
...
不幸的是,命令gnuplot_cmd(h0, "show timefmt");
会产生错误:
警告:空x范围
[1.48323e+09:1.48323e+09],
调整为 [1.4684e + 09:1.49806e + 09]读取时间数据的默认格式为 "%Y-没有这样的文件或目录-0-%H:%M"
为什么%m格式化"没有这样的文件或目录"和%d喜欢" 0" ?
答案 0 :(得分:1)
我已阅读过Gnuplot_i手册,而gnuplot_cmd
命令的参数cmd
应该像printf
函数一样格式化。您的时间格式被解释为格式字符串,因为'%'字符。你应该使用像
gnuplot_cmd(h0, "set timefmt \"%%Y-%%m-%%d-%%H:%%M\"");
gnuplot_cmd(h0, "set format x \"%%H:%%M\"") ;