Search code examples
gnuplot

Using gnuplot instead of excel to plot ping responses


I have a set of data from ping composed of a time stamp and the time, in ms, of the ping response. The time stamp ranges from 08:29:42 and ends at 09:33:54. There is a comma between the time stamp and the ping response. Here is a sample of the actual file:

08:29:42, 4.24

08:29:43, 117

08:29:44, 141

08:29:45, 266

08:29:46, 292

08:29:47, 109

When importing the text file into Excel and highlighting columns A and B and inserting a line chart, I get the following:

excel graph

It is desirable to stay away from Excel and I was hoping to employ gnuplot for this. Specifically because the ping data was collected by a bash script and I could add in the gnuplot functionality to the same script in order to automate things.

Taking the same file and loading it into gnuplot with the following commands:

set term png

set out "gnuplot graph.png"

plot 'ping.txt' with lines

I get the following output:

gnuplot graph

I do not see near the detail in the gnuplot that I see in the excel plot. Additionally the time on the X-Axis only ranges from 08:00-09:00. I would like the graph to take in the entire range from the text file and plot appropriately.

What am I doing wrong in gnuplot for the outputs to be so different?


Solution

  • gnuplot doesn't know that the x data you are using is a time unless you tell it that. Try the following script instead.

    set xdata time
    set timefmt "%H:%M:%S"
    plot "ping.txt" using 1:2
    

    Edit:

    To use lines instead of points add with lines to the end of your plot command:

    set xdata time
    set timefmt "%H:%M:%S"
    plot "ping.txt" using 1:2 with lines
    

    Also I noticed that the data you put in your question has empty lines separating the data points. This will cause your lines to not show up. I highly recommend reformatting your CSV to remove the blank lines.