Problem creating graph with gnuplot with time on x-axis | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Problem creating graph with gnuplot with time on x-axis

Shell Programming and Scripting


Tags
gnuplot

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-04-2013
hakro807 hakro807 is offline
Registered User
 
Join Date: Apr 2013
Last Activity: 19 April 2013, 8:06 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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


Code:
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.


Code:
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.

Last edited by radoulov; 04-04-2013 at 10:09 AM..
Sponsored Links
    #2  
Old 04-04-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 19 December 2014, 8:26 PM EST
Location: Saskatchewan
Posts: 20,037
Thanks: 855
Thanked 3,457 Times in 3,229 Posts
; means 'end of statement', if you want to put another line on your graph after it you should use ,
Sponsored Links
    #3  
Old 04-04-2013
hakro807 hakro807 is offline
Registered User
 
Join Date: Apr 2013
Last Activity: 19 April 2013, 8:06 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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:


Code:
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
Code:
set xdata time

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

Added
Code:
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
Code:
 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?

Last edited by hakro807; 04-04-2013 at 01:50 PM..
    #4  
Old 04-04-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 19 December 2014, 8:26 PM EST
Location: Saskatchewan
Posts: 20,037
Thanks: 855
Thanked 3,457 Times in 3,229 Posts
Your set timefmt looks okay actually, but you also want to add the line set xdata time .
Sponsored Links
    #5  
Old 04-15-2013
hakro807 hakro807 is offline
Registered User
 
Join Date: Apr 2013
Last Activity: 19 April 2013, 8:06 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I succeeded in creating a good-looking graph for the last 60 minutes. Format for data is
Code:
hh:mm value1 value2


Code:
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.
Sponsored Links
    #6  
Old 04-15-2013
verdepollo's Avatar
verdepollo verdepollo is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 19 December 2014, 7:37 PM EST
Location: Mexico
Posts: 725
Thanks: 11
Thanked 106 Times in 102 Posts
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.
Sponsored Links
    #7  
Old 04-16-2013
hakro807 hakro807 is offline
Registered User
 
Join Date: Apr 2013
Last Activity: 19 April 2013, 8:06 AM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by verdepollo View Post
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.. : ]
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Draw Bar Graph for GNUPLOT Tzeronone Programming 0 02-07-2013 01:14 AM
gnuplot flat line graph jamie_123 Shell Programming and Scripting 3 08-31-2012 03:11 PM
GnuPlot - 2d-graph --> depending from size, different color IMPe UNIX and Linux Applications 1 08-18-2012 10:54 PM
Creating a line graph in jqplot figaro Programming 0 04-24-2012 02:07 PM



All times are GMT -4. The time now is 10:57 PM.