如何在时间轴gnuplot图中添加箭头线?解决set变量未定义报错
问题解决:gnuplot时间轴添加标记箭头线
错误原因
- 语法误用:你把
set arrow命令直接嵌入到plot命令的绘图项列表中,gnuplot会将set识别为未定义变量,这是报错的直接原因。set是独立的配置命令,必须单独执行,不能放在plot的逗号分隔项里。 - 时间格式不匹配:箭头中使用的
"103000"不符合你设置的timefmt '%Y-%m-%d, %H:%M'格式,gnuplot无法解析该时间值。
修正后的脚本
clear reset set xdata time set timefmt '%Y-%m-%d, %H:%M' set format x "%H:%M" set datafile separator "," set key left top set title "Test Title" font "sans, 14" set ylabel "ylable title" set xlabel "UT Time" set autoscale y set ytics textcolor rgb "blue" set grid # 单独设置箭头,时间格式与timefmt保持一致 set arrow from "2018-03-02, 10:30",graph 0 to "2018-03-02, 10:30",graph 1 nohead lt 2 lc rgb 'red' lw 2 plot '2018-03-02 naa x ray.csv' u 1:4 w lines lt rgb "red" replot
额外说明
- 如果数据均为同一天(2018-03-02),可以优化时间处理:将数据文件的Date和time列合并为一列(例如
2018-03-02 10:30:00),然后设置timefmt '%Y-%m-%d %H:%M:%S',箭头的时间字符串可写成"2018-03-02 10:30:00",能更精准匹配数据中的秒数。 - 若需添加多条标记线,重复
set arrow命令即可(可添加编号区分,如set arrow 1 ...、set arrow 2 ...)。
内容的提问来源于stack exchange,提问作者Peter
相关产品推荐
相关产品推荐

