Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 我可以对Gnuplot中x轴上显示的自变量进行数学运算吗?_Python 2.7_Datetime_Gnuplot - Fatal编程技术网

Python 2.7 我可以对Gnuplot中x轴上显示的自变量进行数学运算吗?

Python 2.7 我可以对Gnuplot中x轴上显示的自变量进行数学运算吗?,python-2.7,datetime,gnuplot,Python 2.7,Datetime,Gnuplot,这是我的密码: set title "Samples plot" set xlabel "Samples" set ylabel "Volts" set yrange [15:30] set grid unset mouse set timestamp set key center left plot "py.out" using 1:2 skip 2 with lines lw 2 t "Battery", \ "py.out" using 1:3 skip 2 with boxes

这是我的密码:

set title "Samples plot"
set xlabel "Samples"
set ylabel "Volts"
set yrange [15:30]
set grid
unset mouse
set timestamp
set key center left
plot "py.out" using 1:2 skip 2 with lines lw 2 t "Battery", \
     "py.out" using 1:3 skip 2 with boxes t "Inverter", \
     26.0 t "Inverter on", \
     24.8 lw 4 t "Nominal", \
     23.0 t "Inverter off"
数据文件如下所示:

1     22.50    0
2     22.56    0
  (etc, until the inverter turns on at 26) 
5199  25.85    0
5200  26.45    23
5201  24.80    23
  (etc, until it drops below 23 - then the controller cuts it off)
07:01:37.06514  1    24.39    0      <--  \t in between each
07:01:39.10456  2    24.42    0
   etc
显然,样本数是自变量。采样大约每2秒进行一次

除了一个关于Gnuplot的唠叨问题外,我基本上都在我想要的地方

下面是我得到的情节:

所以我的问题是: 如何利用Gnuplot将样本数转换为时间?该系统每小时采集1800个样本。我愿意添加将第一个样本设置为特定时间的代码,并调整每小时的样本数,以使其与实际时间相匹配

更多信息-新的一天: 今天我有9000个样本,从6:00到11:00,我的图是这样的:

1     22.50    0
2     22.56    0
  (etc, until the inverter turns on at 26) 
5199  25.85    0
5200  26.45    23
5201  24.80    23
  (etc, until it drops below 23 - then the controller cuts it off)
07:01:37.06514  1    24.39    0      <--  \t in between each
07:01:39.10456  2    24.42    0
   etc

然后,将plot命令更改为:

    plot "py.out" using (int($1/1800)+6):2 skip 2 with lines lw 2 t "Battery", \
         "py.out" using (int($1/1800)+6):3 skip 2 with boxes t "Inverter", \
使用相同的数据,我得到了如下图形:

1     22.50    0
2     22.56    0
  (etc, until the inverter turns on at 26) 
5199  25.85    0
5200  26.45    23
5201  24.80    23
  (etc, until it drops below 23 - then the controller cuts it off)
07:01:37.06514  1    24.39    0      <--  \t in between each
07:01:39.10456  2    24.42    0
   etc

在plot命令中进行数学运算会导致其更改的不仅仅是轴标记

[已解决] 我没有让GNUPLOT单独用数学来处理这个问题,而是首先改变了数据输入的方式,然后让GNUPLOT来处理它

最初,我使用这个简单的python程序将其保存到一个用于打印的文件中:

import serial
ser = serial.Serial("/dev/ttyUSB0",9600)
while 1:
    c = ser.readline()
    f = open("py.out","a")
    f.write(c)
    f.close
因此,我将其更改为在传入数据流中包含时间:

import serial
from datetime import datetime
ser = serial.Serial("/dev/ttyUSB0",9600)
while 1:
    c = str(datetime.now().time()) + '\t' + ser.readline()
    f = open("py.out","a")
    f.write(c)
    f.close
数据如下所示:

1     22.50    0
2     22.56    0
  (etc, until the inverter turns on at 26) 
5199  25.85    0
5200  26.45    23
5201  24.80    23
  (etc, until it drops below 23 - then the controller cuts it off)
07:01:37.06514  1    24.39    0      <--  \t in between each
07:01:39.10456  2    24.42    0
   etc
07:01:37.06514124.390


并使用一个“使用”说明符,将样本数转换为自午夜起的秒数(实际上是自1970年1月1日0:00h起,但这并不重要,因为您不显示日期)。使用(int($1/1800)+6)的说明符
完全是胡说八道,我不明白您希望它做什么。

这个问题包含了不必要的细节。考虑到我们中的很多人都有有限的时间来帮助你,所以把你的问题缩小到你需要解决的实际问题上,并提供一个你的代码的最小的工作例子,这将提高别人帮助你的机会。顺便说一句,这也将提高这个问题和任何最终答案对其他人也有用的机会。谢谢你的评论,@Miguel。您将看到您建议的更改。向上投票。您可能希望在
int($1/1800)+6
中删除对
int
的调用-否则,一小时内的所有数据点都会压缩为一个垂直线段,如图所示,例如,上一个绘图中的红线。谢谢你的提示。向上投票,向上投票。谢谢你的提示。我同意我尝试过的代码。我对GNUPLOT还比较陌生,但现在进展很好。它不像SAS,但它确实能够用很少的code.Tnx做很多事情。顺便说一句,它的拼写是
gnuplot
,第一个大写字母仅出现在句子的开头。Godd idea,用于存储实际日期,而不是根据运行中的数据点数量进行重建。但是,如果您不关心实际日期/时间,请记住gnuplot可以轻松地将连续数据点的数量转换为秒数,然后转换为分钟、小时等,只用于输出,而不需要对实际数据集进行任何更改。