简体   繁体   English

python gnuplot读取csv文件以按读取顺序或行顺序在x轴上绘制时间

[英]python gnuplot read csv file to plot time in x-axis in the read order or row order

I have csv file in the below format with more than 3k rows and 20 columns 我有以下格式的csv文件,超过3k行和20列

21:46:12    82748   5356864
22:47:33    82748   5352768
23:47:43    82748   5356864
00:47:53    82748   5356864
01:48:03    82748   5352768
02:48:13    82748   5356864
03:48:23    82748   5352768
04:48:33    82748   5356864

When i tried to draw graph, the time is getting ordered from 04 to 21 where as my requirement is to draw in the same row order ie 21 to 04 (i don't have date entry to order). 当我尝试绘制图形时,时间从04到21排列,其中我的要求是以同一行顺序绘制,即21到04(我没有按顺序输入日期)。 is there any mechanism to maintain the same order to draw the plot. 是否有任何机制可以维持绘制绘图的相同顺序。

( Edit: see at the bottom for the time-specific solution ) 编辑:请参阅底部的特定时间解决方案

With this answer you'll need to work a bit on your specifics, but the solution is basically this. 有了这个答案,您将需要针对您的具体情况进行一些工作,但是解决方案基本上是这样。

I suggest that you use a counting system, storing in some variable whenever you increase by one day, which happens every time the value in column one is less than the previous value, eg 22:00:00 followed by 01:00:00. 我建议您使用一种计数系统,每增加一天,它就会存储在某个变量中,这种情况每发生在第一列中的值小于以前的值时,例如22:00:00后跟01:00:00。 Consider the following data: 考虑以下数据:

0 1
1 2
2 3
3 4
0 5
1 6
2 7
3 8

The cycle happens every 4 units (it would be 24 hours in your case). 该周期每4个单位发生一次(在您的情况下为24小时)。 Plotted as is, this would look like this: 按原样绘制,如下所示:

在此处输入图片说明

Now, with the following code you can keep track of "jumps" in the x value: 现在,使用以下代码,您可以跟踪x值中的“跳转”:

count=0
x0=1
plot "data" u ($1 < x0 ? (x0=$1, count=count+1, $1+4.*count) : \
(x0=$1, $1+4.*count) ):2 w l

The code above increases count by one if the current x value is lower than the previous one. 如果当前x值小于前一个,则上面的代码将count加1。 Then the x value is shifted to x + 4.*count . 然后,将x值移至x + 4.*count Four is my cycle width (24 hours for you). 四是我的周期宽度(24小时为您服务)。 This looks as below: 如下所示:

在此处输入图片说明

Time-specific solution: 特定时间的解决方案:

Same principle, applied to OP's question: 相同原则适用于OP的问题:

set xdata time
set timefmt "%H:%M:%S"
set format x "%d - %H:%M:%S"
set xtics 6*3600
count = 0
x0 = 0
plot "data" u (timecolumn(1) < x0 ? (x0=timecolumn(1), count=count+1, \
$1+24*3600*count) : (x0=timecolumn(1), timecolumn(1)+24*3600*count) ):3 w l

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM