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

与世无争的帅哥 提交于 2020-01-05 18:52:55

问题


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

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.


回答1:


(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, 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

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

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

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:

Time-specific solution:

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



来源:https://stackoverflow.com/questions/25308739/python-gnuplot-read-csv-file-to-plot-time-in-x-axis-in-the-read-order-or-row-ord

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!