Rory
Rory

Reputation: 4320

Plotting a single value with gnuplot?

I have the following csv file:

timestamp,unit,maximum,average
Thu Feb 05 14:54:00 GMT 2015,Percent,13.0,4.503333333333333

When I run the following bash script on it:

#!/bin/bash

graph_results() {
  input=cpu-samples.csv
  output=cpu-samples.png
gnuplot <<- eor
  set terminal png 
  set output '${output}'
  set style data linespoints
  set xdata time
  set timefmt '%b %d %H:%M:%S GMT %Y'
  set format x '%b %d %Y %H:%M'
  set datafile separator ","
  set xlabel "timestamp"
  set ylabel "percent"
  set xtics rotate
  plot '< tail -n +2 ${input} | cut -f 1 --complement -d" "' using 1:3 title 'Maximum', '' using 1:4 title 'Average'
eor
}

graph_results

I get the following error:

bash-4.1$ ./run_gnuplot 
Could not find/open font when opening font "arial", using internal non-scalable font
Warning: empty x range [4.76463e+08:4.76463e+08], adjusting to [4.71699e+08:4.81228e+08]

And the resulting graph has the correct datapoint and timestamp on it, but the graph is filled out with incorrect date values for the x axis.

It works fine when the csv file has more than one value in it, but doesn't when there is only one value. I realize the error message is because with one value, the start and end range for the x axis is the same (as noted here http://gnuplot.10905.n7.nabble.com/empty-x-range-td1650.html).

I know I can set a range with the following:

set xrange

But unsure how I could use in in my case, since I'm using a custom date format, and I don't know what the start and end dates should be, since the data generated is dynamic?

Upvotes: 1

Views: 698

Answers (1)

Christoph
Christoph

Reputation: 48420

When using a custom timefmt, the xrange must also be specified using this format:

set xrange ["Feb 04 00:00:00 GMT 2015":"Feb 09 00:00:00 GMT 2015"]

Or you can integers, i.e.a timestamp to set the xrange. With version 5.0 the line below is equivalent to the string settings above:

set xrange [1423008000:1423440000]

Note, that until version 4.6 gnuplot uses the first january 2000 as time reference for its timestamps, and only since 5.0 the standard Unix timestamp. So until 4.6, the equivalent command to the string settings in the first line would be

set xrange [476323200:476755200]

Upvotes: 0

Related Questions