Question

How to correctly plot special time format HMMSS?

Through the use of BASH scripts, I am pinging 50+ devices on a computer network, and tracking when these devices fail. Using sed and some other utilities, when a ping fails to return, it is recorded in a CSV file, and processed 3 times a day.

The CSV file is in the format, such as Input data (CSV)

 6    92121
 3    93237
 2    93828
 2    95409
 4    95439

 3   101045
 3   102515
 2   105211

where we see the amount of failures first, followed by the time, with the : marks stripped out. This causes GNUPlot to see "time" as a whole integer.

When the above range is plotted, we see the following (clipped for focus):

enter image description here

Looking at the chart, I think that the + marks should be shifted a bit further to the right, as they don't appear to be aligning where I think they should. 4 minor ticks in from 80000 would be 90000, and two more ticks to the right would be 95000. My next data point is at 95409 which I would expect to be closer to 100000 than how it appears.

Perhaps this is a mind-game because I am plotting time which is based on 60 units, to a graph that is based on units of ten. HH:MM:SS format. 100000 is 10:00:00 and while 10:50:27 exists (105027 to GNUPlot), we won't see 10:75:13 (107513) because of the time rollover @ 60 min. I wonder if GNUPlot can be told X axis is time oriented in that fashion...

The second question is how to explicitly tell GNUPlot to label every X tick, reducing the interpreted guess of the X values.

Here is my GNUPlot command:

gnuplot <<-EOFMarker
set datafile separator ','
set title "Devices failing pings at given time - Graph Created:  UTC "
set xlabel 'Time in HH:MM:SS -- 6am run missing leading zero'
set ylabel 'Amount of Sites with Dropped Pings'
set yrange [1:75]
set grid
set key off
set xtics  rotate
set mxtics 8
set terminal png size 4000,700
set output '/BigPing/Reports/${reporttime}-${checkhour}-sites-time.png'
plot '/mnt/ram/graph-input.dat' using 2:1
EOFMarker

Originally I had lines connecting the + points to increase readability, but the graph didn't return to Zero like I though it would when we didn't have data present.

I was expecting more xtick labels so the gaps would not be so large.

Actually, I'm bound to use gnuplot 4.6.2

 2  57  2
1 Jan 1970

Solution

 2

Of course, gnuplot can plot time data (check help timecolumn and help time_specifiers), however, your time data format is a bit unfortunate. For example, gnuplot will have difficulties to decide whether 12345 will be 1h 23 m 45 s or 12 h 34 m 5 s. Hence you have to make sure that the number has 6 digits, i.e. with leading zero. You can force this via sprintf("%06d",...). Then you can easily decode this time with the specifier string "%H%M%S".

Script: (works for gnuplot>=5.0.0, Jan. 2015)

### plot special time format
reset session

$Data <<EOD
 6    92121
 3    93237
 2    93828
 2    95409
 4    95439

 3   101045
 3   102515
 2   105211
EOD

t(col) = strptime("%H%M%S", sprintf("%06d",column(col)))

set format x "%H:%M" timedate
set offset graph 0.05, 0.05, 0.05, 0.05
set grid x,y
set key noautotitle

plot $Data u (t(2)):1 w p pt 7 lc "red"
### end of script

Result:

enter image description here

Addition: version for gnuplot>=4.6.0, output same as graph above.

Data: SO78770582.dat

 6    92121
 3    93237
 2    93828
 2    95409
 4    95439

 3   101045
 3   102515
 2   105211

Script: (works at least for gnuplot>=4.6.0, March 2012)

### plot special time format
reset

FILE = "SO78770582.dat"

t(col) = strptime("%H%M%S", sprintf("%06d",column(col)))

set xdata time
set format x "%H:%M"
set offset graph 0.05, 0.05, 0.05, 0.05
set grid x,y
set key noautotitle

plot FILE u (t(2)):1 w p pt 7 lc rgb "red"
### end of script
2024-07-19
theozh

Solution

 0

With great thanks to @theozh, I was able to assemble the proper code for my case. I am thankful for the hints. I removed some materials inside the quotations in order to avoid wrap around.

gnuplot <<-EOFMarker
        set datafile separator ','
        set terminal png size 2000,500
        set title "Pings at given time - Graph Created:  UTC "
        set xlabel 'Time in HH:MM''
        set ylabel 'Amount of Sites with Dropped Pings'
        t(col) = strptime("%H%M%S", sprintf("%06d",column(col)))
        set xdata time
        set format x "%H:%M"
        set offset graph 0, 0, 0, 0.05
        set grid x,y
        set key noautotitle
        set output '/BigPing/Reports/${v1}-${v2}-sites-time.png'
        plot '/mnt/ram/graph-input.dat' u (t(2)):1 w p pt 7 lc rgb "red"
EOFMarker
2024-07-22
CyberdocWI