如何在 feedgnuplot 中使用 gnuplot xdata 时间?
How to use gnuplot xdata time with feedgnuplot?
我正在使用 feedgnuplot 和 gnuplot 在我的 linux 桌面上显示实时数据。
我的数据是由命令生成的,该命令在每行上输出 12 space 个分隔的整数值,每秒最多输出四行。
我喜欢添加时间,所以我在将数据提供给 feedgnuplot 之前将时间放在行的前面。
如果我将时间指定为秒,则可以正确绘制数据,但 x 轴非常难读:
data-producer |
while read -a line
do
echo -n $(date +"%s")
for n in "${line[@]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%s'"
所以我试图在水平尺度上获得人类可读的时间:
data-producer |
while read -a line
do
echo -n $(date +"%H:%M:%S")
for n in "${line[@]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%H:%M:%S'"
此行不起作用,因为 feedgnuplot 抱怨比较运算符未应用于数字数据:
Argument "09:45:58" isn't numeric in numeric lt (<) at /usr/bin/feedgnuplot line 694.
Argument "09:45:57" isn't numeric in numeric ge (>=) at /usr/bin/feedgnuplot line 797.
查看 feedgnuplot 代码(它是一个 perl 脚本)我看到对 x 值执行比较以对它们进行排序并评估是否必须再次绘制图形。
是否可以通过使用一些命令行开关来获得 feedgnuplot 处理时间?如果没有,在修补 feedgnuplot 源代码之前还有其他选择吗?谢谢。
Gnuplot 需要对日期时间数据进行一些特殊设置(例如,必须指定 using
语句)。因此,feedgnuplot
为时间数据提供了自己的选项,--timefmt <format>
:
for i in `seq 0 100`; do echo $i; sleep 1; done |
while read -a line
do
echo -n $(date +"%Y-%m-%d %H:%M:%S")
for n in "${line[@]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--lines \
--timefmt "%Y-%m-%d %H:%M:%S" \
--set 'format x "%H:%M:%S"'
请注意,不同版本的 gnuplot 使用不同的时间参考点(以秒为单位),因此 4.6 版(参考 2000 年 1 月 1 日)及更早版本在使用 %s
时会给出错误的结果。所以最好使用 %H:%M:%S
这种时间格式。在上面的代码中,我使用了一个完全定义的日期时间来避免跨日图可能出现的问题。
我正在使用 feedgnuplot 和 gnuplot 在我的 linux 桌面上显示实时数据。 我的数据是由命令生成的,该命令在每行上输出 12 space 个分隔的整数值,每秒最多输出四行。 我喜欢添加时间,所以我在将数据提供给 feedgnuplot 之前将时间放在行的前面。 如果我将时间指定为秒,则可以正确绘制数据,但 x 轴非常难读:
data-producer |
while read -a line
do
echo -n $(date +"%s")
for n in "${line[@]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%s'"
所以我试图在水平尺度上获得人类可读的时间:
data-producer |
while read -a line
do
echo -n $(date +"%H:%M:%S")
for n in "${line[@]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--xlen 5 \
--with lines \
--set "xdata time" \
--set "timefmt '%H:%M:%S'"
此行不起作用,因为 feedgnuplot 抱怨比较运算符未应用于数字数据:
Argument "09:45:58" isn't numeric in numeric lt (<) at /usr/bin/feedgnuplot line 694.
Argument "09:45:57" isn't numeric in numeric ge (>=) at /usr/bin/feedgnuplot line 797.
查看 feedgnuplot 代码(它是一个 perl 脚本)我看到对 x 值执行比较以对它们进行排序并评估是否必须再次绘制图形。
是否可以通过使用一些命令行开关来获得 feedgnuplot 处理时间?如果没有,在修补 feedgnuplot 源代码之前还有其他选择吗?谢谢。
Gnuplot 需要对日期时间数据进行一些特殊设置(例如,必须指定 using
语句)。因此,feedgnuplot
为时间数据提供了自己的选项,--timefmt <format>
:
for i in `seq 0 100`; do echo $i; sleep 1; done |
while read -a line
do
echo -n $(date +"%Y-%m-%d %H:%M:%S")
for n in "${line[@]}"
do
echo -en "\t$n"
done
echo
done |
feedgnuplot --terminal 'qt' \
--domain \
--stream 1 \
--lines \
--timefmt "%Y-%m-%d %H:%M:%S" \
--set 'format x "%H:%M:%S"'
请注意,不同版本的 gnuplot 使用不同的时间参考点(以秒为单位),因此 4.6 版(参考 2000 年 1 月 1 日)及更早版本在使用 %s
时会给出错误的结果。所以最好使用 %H:%M:%S
这种时间格式。在上面的代码中,我使用了一个完全定义的日期时间来避免跨日图可能出现的问题。