Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Gnuplot Question

15 views
Skip to first unread message

Beery

unread,
May 16, 2013, 10:15:17 PM5/16/13
to
Not sure if this is the right group...

I have a data file of the following format:

servername,2013-05-11 17:46:03,SomeText,195,195,11,202
servername,2013-05-11 17:47:03,SomeText,192,192,23,103
servername,2013-05-11 17:48:03,SomeText,189,190,14,117
servername,2013-05-11 17:49:03,SomeText,196,195,24,231
...
...

I want to plot a graph where the x-axis has the time (%H:%M:%S) values (don't need the date part. The y-axis should have the two last columns.

Here's a sample bash script I have to run this.

#!/usr/bin/bash

basedir="app-stats"
termsize="1200,600"
xtics="1800"
type="proc"
range="*:"

echo $server-$filenm.data

gnuplot -persist << EOF
reset
set terminal pngcairo size ${termsize} enhanced font 'Verdana,8'
set xdata time
set timefmt "%Y/%m/%d %H:%M:%S'"
set format x "%H:%M:%S"
set datafile separator ","
set xtics nomirror rotate
set xtics ${xtics}
set ytics nomirror
set y2tics
set grid xtics lt 0 lw 1 lc rgb "#000000"
set grid ytics lt 0 lw 1 lc rgb "#880000"
set grid y2tics lt 0 lw 1 lc rgb "#008800"
set ylabel 'servername'
set y2label 'proc'
set auto fix
set offsets graph 0, graph 0, graph 0.1, graph 0
show offsets
set title "App Statistics for ${host}" enhanced font 'Verdana Bold,10'
set label "Date: 02/07/13" at screen 0.01, 0.97
set label "SomeLabel" at screen 0.98, 0.97 right
set key inside center bottom horizontal Right noreverse enhanced autotitles box linetype -1 linewidth 1.000

set output "$server-$filenm.png"
plot '$server-$filenm.data' using 1:6 title 'proc/s' with lines lt rgbcolor "light-red" lw 2, \
'$server-$filenm.data' using 1:7 axes x1y2 title 'cswch/s' with lines lt rgbcolor "blue" lw 2
EOF

exit


I can plot this successfully if the time data doesn't contain "date space time" but only time and the server name isn't the first field (see below).

17:46:03,SomeText,195,195,11,202
17:47:03,SomeText,192,192,23,103
...
...

My questions are:

1. Can I have a non-xdata column before the xdata column like "servername" and identify where the xdata column is in the "using (1:6)" statement, substituting 1:6 with say, 3:6 if the xdata column is the third column? I'm not able to get this to work.

2. If the first column is

2013-05-11 17:46:03, how can I get it to plot correctly using either

set timefmt "%Y/%m/%d %H:%M:%S'"
set format x "%H:%M:%S"

or

set timefmt "%Y/%m/%d %H:%M:%S'"
set format x "%Y/%m/%d %H:%M:%S"

Cheers,
Beery

Janis Papanagnou

unread,
May 17, 2013, 3:20:44 AM5/17/13
to
On 17.05.2013 04:15, Beery wrote:
> Not sure if this is the right group...

Probably not. :-)

And I see you already multi-posted the same questions to the gnuplot group.

Every other year when I'm doing some graphs with gnuplot I have to study
that tool again; so I can only provide some example that may or may not help
you, and you certainly have to map relevant information to your problem.

>
> I have a data file of the following format:
>
> servername,2013-05-11 17:46:03,SomeText,195,195,11,202
> servername,2013-05-11 17:47:03,SomeText,192,192,23,103
> servername,2013-05-11 17:48:03,SomeText,189,190,14,117
> servername,2013-05-11 17:49:03,SomeText,196,195,24,231
> ...
> ...
>
> I want to plot a graph where the x-axis has the time (%H:%M:%S) values (don't need the date part. The y-axis should have the two last columns.

I had been plotting weather data, temperature and rain also on two axis; I
assume by "two columns" you mean something like that.

Here is my data format (separated in two files in my case):

==> temp.plot <==
10.03.2012 05:00 0�C
10.03.2012 08:00 4�C

==> rain.plot <==
10.03.2012 05:00 0.01
10.03.2012 08:00 0.01

And the gnuplot script:

set title "...\n\n"
set locale "de_DE.utf8"
set decimalsign '.'
set xdata time
set timefmt "%d.%m.%Y"
set format x "%a.\n%d."
set timefmt "%d.%m.%Y %H:%M"
set xlabel "Datum"
set ylabel "Temperatur [�C]"
set y2label "Niederschlag [mm]"
set yr [-20:+60+-20]
set y2r [0:12]
set xtics 86400
set mxtics 8
set ytics 10
set mytics 2
set y2tics 1
set my2tics 10
set xtics offset first 86400/2
set ytics nomirror
set grid
set xzeroaxis ls 4
set term png size 800+12, 600
set output "wetter_tmp.png"

plot "temp.plot" using 1:3 title 'Temperatur' smooth csplines, \
"rain.plot" using 1:3 axis x1y2 title 'Niederschlag' smooth csplines lt 3

It creates output with two different scales on the left and right side, for
temperature and rain respectively. From the two time information data columns
the script is creating just the "Day of the week" name and the "Day in month"
number.

Hope it's of some use.

One more thing; if it's the two different delimiters (comma and blank) that
is the problem in your script you may want to pre-process that data first.

Janis
0 new messages