在同一图中绘制日期/时间数据点和功能 [英] Plotting date/time data points and functions in the same graph

查看:111
本文介绍了在同一图中绘制日期/时间数据点和功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制一组日期/时间数据点,并使用unix纪元指定的x值(自1970年以来的秒数).我还想绘制一个趋势函数以及数据(是的,我知道gnuplot可以为我完成此操作,但这是一个示例).所以我有如下所示的data.txt:

I want to plot a set of date/time data points with the x value specified by unix epoch, seconds since 1970. I also want to plot a trend function along with the data (yes I know gnuplot can do this for me, but this is an example). So I have data.txt that looks like this:

1303430400 67.5
1303862400 65.5
1304208000 62.9
1304553600 60.2

我有一个gnuplot程序,看起来像这样:

And I have a gnuplot program that looks like this:

set terminal png
set output 'plot.png'
set timefmt "%s"
set xdata time
plot "data.txt" using 1:2 title "Data points", \
    -7.0/(1123200)*x + 8190.43 title "Trend"

现在,该函数只是数据的线性近似.我已经检查了公式,应该没问题.例如,插入1304553600(范围的最后一个值),您将得到60.2.

Now, the function is simply a linear approximation of the data. I have checked the formula and it should be ok. For instance, plugging in 1304553600 (the last value of the range), you get 60.2.

我希望看到我的数据点以及随数据点大致跟踪的函数.取而代之的是函数图,大约太高了6000.显然,我对日期/时间图不了解.我应该怎么做才能获得预期的结果?

I would expect to see my data points plotted along with the function roughly following the data points. Instead, the function plot is way off, about 6000 too high. Apparently I do not understand something about date/time plots. What should I do to get my expected result?

推荐答案

我在手册页中发现了这一点:"[在日期图中] gnuplot也将接受一个整数表达式,该表达式将被解释为从2000年1月1日开始的秒数. "

I found this in the man page: "[In date plots] gnuplot will also accept an integer expression, which will be interpreted as seconds from 1 January 2000."

Unix纪元与gnuplot时间之间存在946684800秒的差异.此gnuplot脚本给出了预期的绘图(请注意x的946684800附加内容):

There is a difference of 946684800 seconds between unix epoch and gnuplot time. This gnuplot script gives the expected plot (note the 946684800 addition to x):

set terminal png
set output 'plot.png'
set timefmt "%s"
set xdata time
plot "stackoverflow.txt" using 1:2 title "Data points", \
    -7.0/(1123200)*(x+946684800) + 8190.43 title "Trend"

这篇关于在同一图中绘制日期/时间数据点和功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆