无法更改 gnuplot 中的日期格式

问题描述 投票:0回答:1

我想在使用 csv 文件加载数据时调整 x 轴格式。下面的脚本不适用于关联的数据。

min_example.csv

12-03 17:40:54,6
12-03 18:40:54,5
12-03 19:40:54,9
set datafile separator ","
set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%d %H"
plot 'min_example.csv' using 1:2:xtic(1)

输出仍为“%d-%m %H:%M:%S”格式。 非常感谢!

当使用包含更多数据的数据集(例如 12/4)时,它仍然可以按日期和时间正确排序,但我无法修改其他任何内容。 xtics 是一个明确的列表。我已经检查过“空格”字符不是 ;这绝对是一个空间。

bash csv gnuplot gnu
1个回答
0
投票

您的脚本使用命令

plot ... using 1:2:xtic(1)
绕过了 x 轴 tic 标签的正常格式。
xtic(1)
部分告诉它使用第1列中的内容(即字符串)作为tic标签。

您需要将新格式应用于第 1 列中的字符串表示的时间值,而不是字符串本身。第 1 列中的字符串表示的时间值可以通过

timecolumn(1)
来访问。让我们定义一个函数来将新格式应用于时间值:

reformat(time) = strftime("%d %H", time)

现在重写脚本以在绘图中使用该函数

$DATA << EOF
12-03 17:40:54,6
12-03 18:40:54,5
12-03 19:40:54,9
EOF

set datafile separator ","
set xdata time
set timefmt "%d-%m %H:%M:%S"
reformat(time) = strftime("%d %H", time)
plot '$DATA' using 1:2:xtic(reformat(timecolumn(1)))

© www.soinside.com 2019 - 2024. All rights reserved.