Problem creating graph with gnuplot with time on x-axis

Let me start by saying I'm new to gnuplot and not very good at unix at all..

Anyway, I'm each minute measuring temperature and humidity and saves the last 60 readings along with time in a textfile, values_minute.

The contents of the file is formatted like this: time temperature humidity

14:10 22.8 19.1
14:11 22.8 19.1
14:12 22.8 19.1
14:13 22.8 19.0
14:14 22.8 19.0
14:15 22.8 19.0
14:16 22.8 19.0
etc...

I'm trying to create a graph using gnuplot, working with the shell first. Later I will do it with a script that will run once a minute to generate a "realtime" graph to be publish on a web site.

gnuplot
set terminal png
set output "graph_realtime.png"
set yrange [10:50]
plot "./values_minute" using 1:2 title 'Temperature' with lines; \
"./values_minute" using 1:3 title 'Humidity' with lines

But I'm given the error "invalid command". I'm quite frankly lost.

; means 'end of statement', if you want to put another line on your graph after it you should use ,

I just realised the code I posted was incomplete. Since the x axis is time gnuplot has to be told so.

So the final code looks like this:

gnuplot
set terminal png
set output "graph_realtime.png"
set yrange [10:50]
set timefmt "%H:%M"
plot "./values_minute" using 1:2 title 'Temperature' with lines, \
"./values_minute" using 1:3 title 'Humidity' with lines

This works without giving an error message, but all the values is located at the extreme ends of the graph.

Added

set xdata time

which helped. But now I need to make the x axis easily readable, maybe tics every 15 minutes.

Added

set xtics "14:00", 900, "16:00"

which help but it's still showing the time as hours:minutes:seconds, how to only show it as hours:minutes? And does it exist an easy way to replace (in my example) 14:00 and 16:00 with proper values, i.e. if it was measured from 09:05 to 10:04 the first tic (excluding the edges of the graph) would be at 09:15, the last at at 10:00? I guess it's similar to

 set xtics "%H:M", 900, "%H:%M"

or do I have to create a script that read the first and last value from the table with values and insert the correct time?

Your set timefmt looks okay actually, but you also want to add the line set xdata time .

I succeeded in creating a good-looking graph for the last 60 minutes. Format for data is

hh:mm value1 value2
set terminal png
set output "hour_graph.png"
set yrange [10:50]
set ylabel "Temperatur Celsius/Luftfuktighet procent"
set timefmt "%H:%M"
set xdata time
set xtics "00:00", 900, "24:00" #guess it will mess up temporarily at 24:00
set mxtics 3 #a small tic every five minute
set format x "%H:%M" #set format x was needed to format the x axis as hh:mm, not hh:mm:ss

plot "./hour_graph_values" using 1:2 title 'Temperatur' with lines, \
"./hour_graph_values" using 1:3 title 'Luftfuktighet' with lines

Would still love to know the syntax for letting gnuplot deal with both date and time.
At the moment the main log is in the following format:
yyyy-mm-dd hh:mm value1 value2

I just can't believe gnuplot would not be able to deal with something which most be so common.

I am by no means a gpuplot expert but from the description of your original post, sounds like rrdtool might just be a tailor-made tool for what you're trying to achieve.

It's too late for me to start anew, but I'll keep rrdtool in mind in case a similar assignment shows up later. Still, I appreciate you taking the time.

Looking back I wish I had just used epoch time, i.e. seconds since 1/1 1970. It would most likely have made it so much easier. Oh well, we live, we learn.. : ]

epoch time would indeed be much easier, but gnuplot has its own issues there as well. UNIX measures epoch since 1970, GNUplot measures epoch since 2000-something. Why? Who knows! But fixing that is just arithmetic...

You can use GNU awk to convert those times into epoch times:

awk -F"[:- ]" '{ $0=(mktime($1" "$2" "$3" "$4" "$5" 00")+OFF)" " $6" "$7 } 1' OFF="-21600" inputfile > outputfile

You may need to add or subtract a certain number of seconds to match your time zone. -21600 is GMT-6.