Format 通过gnuplot解析带值的时间戳和绘图

Format 通过gnuplot解析带值的时间戳和绘图,format,timestamp,gnuplot,Format,Timestamp,Gnuplot,我有这些data.txt: [1384395497218,679],[1384399097218,679],[1384402697218,679]... [timestamp,value] 其中第一个是时间戳1384395497218->1384395497.218->Thu,2013年11月14日02:18:17 GMT。 第二个是计数 我想在x轴上绘制带有日期的直线图,在y轴上计数。我该怎么做 Example: x-axis = "14 November" y-axis = "679".

我有这些data.txt:

[1384395497218,679],[1384399097218,679],[1384402697218,679]...

[timestamp,value]
其中第一个是时间戳1384395497218->1384395497.218->Thu,2013年11月14日02:18:17 GMT。 第二个是计数

我想在x轴上绘制带有日期的直线图,在y轴上计数。我该怎么做

Example:
x-axis = "14 November" y-axis = "679"..

这是一种非常奇怪的输入格式。如果可以,你应该选择一个更合适的。Gnuplot无法处理此问题,必须在打印数据文件之前对其进行预处理。这可以通过使用
perl
和正则表达式来实现,如下所示:

如果您有一个包含以下值的数据文件
test.txt

[1384395497218,679],[1384399097218,679],[1384402697218,679]
并在命令行上使用以下调用:

perl -pe 's/\[(\d+)([\d]{3}),(\d+)\],?/\1.\2 \3\n/g' test.txt
您将数据格式化为

1384395497.218 679
1384399097.218 679
1384402697.218 679
可以用gnuplot绘制。要动态完成预处理,请使用以下语法

plot '< perl ...'
plot'
数据的简短脚本如下:

set timefmt '%s'
set xdata time
set format x '%d %B'
set xtics 24*60*60
getdata = '< perl -pe ''s/\[(\d+)([\d]{3}),(\d+)\],?/\1.\2 \3\n/g'' test.txt'
plot getdata using 1:2 with linespoints notitle
set timemt“%s”
设置扩展数据时间
设置格式x“%d%B”
设置xtics 24*60*60
getdata='
还有一些注意事项:

  • 时间格式
    %s
    读取时间戳,时间戳也可以有十进制数字(您也可以删除它们)
  • 设置xtics 24*60*60
    每天设置一个主要tic
  • 使用
    设置格式x“%d%B”
    可以为x轴上的时间输出格式设置不同的格式
4.6.4的结果是: