python gnuplot读取csv文件以按读取顺序或行顺序在x轴上绘制时间 [英] python gnuplot read csv file to plot time in x-axis in the read order or row order

查看:392
本文介绍了python gnuplot读取csv文件以按读取顺序或行顺序在x轴上绘制时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下格式的csv文件,具有超过3k行和20列

I have csv file in the below format with more than 3k rows and 20 columns

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

当我尝试绘制图形时,时间是从04到21排序的,因为我的要求是绘制同一行顺序,即21到04(我没有要输入日期的命令).是否有任何机制可以维持绘制绘图的相同顺序.

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 i.e 21 to 04 (i don't have date entry to order). is there any mechanism to maintain the same order to draw the plot.

推荐答案

(针对特定时间的解决方案,请参见底部)

有了这个答案,您需要在细节上做一些努力,但是解决方案基本上是这样.

With this answer you'll need to work a bit on your specifics, but the solution is basically this.

我建议您使用一种计数系统,每增加一天,它就会存储在某个变量中,这种情况每发生在第一列中的值小于以前的值时,例如22:00:00,然后是01:00:00.考虑以下数据:

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, e.g. 22:00:00 followed by 01:00:00. Consider the following data:

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

该周期每4个单位发生一次(在您的情况下为24小时).按原样绘制,如下所示:

The cycle happens every 4 units (it would be 24 hours in your case). Plotted as is, this would look like this:

现在,使用以下代码,您可以跟踪x值中的跳转":

Now, with the following code you can keep track of "jumps" in the x value:

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

如果当前x值小于前一个,则上面的代码将count加1.然后,x值移至x + 4.*count.四是我的周期宽度(24小时为您服务).如下所示:

The code above increases count by one if the current x value is lower than the previous one. Then the x value is shifted to x + 4.*count. Four is my cycle width (24 hours for you). This looks as below:

特定时间的解决方案:

相同的原则,适用于OP的问题:

Same principle, applied to OP's question:

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

这篇关于python gnuplot读取csv文件以按读取顺序或行顺序在x轴上绘制时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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