Skip to content Skip to sidebar Skip to footer

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 21:46:12 82748 5356864 22:47:33 82748 5352768 23:47:43 82748 5356864 00:47:53 82748 53

Solution 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:

enter image description here

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:

enter image description here

Time-specific solution:

Same principle, applied to OP's question:

set xdata time
set timefmt "%H:%M:%S"
set formatx"%d - %H:%M:%S"
set xtics 6*3600
count = 0x0 = 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

enter image description here

Post a Comment for "Python Gnuplot Read Csv File To Plot Time In X-axis In The Read Order Or Row Order"