5

From these data I can create a diagram in OpenOffice:

$ cat time.log 
2014-04-29 08:15:34 1.00
2014-04-29 08:15:36 1.00
2014-04-29 08:15:42 1.50
2014-04-29 08:15:47 2.00
2014-04-29 08:15:55 2.00
2014-04-29 08:16:02 3.00
2014-04-29 08:16:10 4.00
2014-04-29 08:19:31 6.00
$ 

enter image description here

Q: But how can we create the same diagram with a console program? Are there any diagram generator applications on Linux (using Ubuntu 12.04)? A "time.txt" can have an average 200 lines.

p.s.: these are outputs from command execution:

$ { /usr/bin/time -f "%e" sleep 6 ; } 2>&1 | sed "s/^/`date "+%F %H:%M:%S"`\t/g" >> time.log
1

3 Answers 3

1

As others have already pointed to out, Gnuplot is the right tool for the job. Below is shell script for collecting the data and generating a histogram from the data with Gnuplot:

#!/bin/sh
LOGFILE=./time.log
OUTFILE=./time-plot.png

{ /usr/bin/time -f "%e" sleep 6 ; } 2>&1 | sed "s/^/`date "+%F %H:%M:%S"`\t/g" >> "$LOGFILE"

gnuplot << EOF
set lmargin at screen 0.20
set rmargin at screen 0.85
set bmargin at screen 0.30
set tmargin at screen 0.85
set datafile separator " "
set title ""
set ylabel ""
set yrange [0:7]
set xlabel ""
set xtics rotate by 45 right
set style fill solid 1.00 noborder
set boxwidth 2 relative
set terminal png
set output "$OUTFILE"
plot "$LOGFILE" using 3:xticlabels(stringcolumn(1) . " " . stringcolumn(2)) with histogram notitle linecolor rgb 'blue'
EOF

An example plot generated for the sample data provided below:

Example plot generated from sample input

Note that this example uses the tic alignment options introduced in Gnuplot 4.6.0 to match the x-axis label rotation in the sample diagram. The right, left and center tic alignment options are not available in the Gnuplot 4.4.3 packaged for Ubuntu 12.04. If the precise appearance is not an issue, replace set xtics rotate by 45 right with for instance set xtics rotate to make the script compatible with the older version of Gnuplot.

1

You could use latex for this purpose. Just make yourself an appropriate template and afterwards cut them together. A quick and dirty example assuming your time.log looks a bit more parser friendly:

2014-04-29 08:15:34, 1.00
2014-04-29 08:15:36, 1.00
2014-04-29 08:15:42, 1.50
2014-04-29 08:15:47, 2.00
2014-04-29 08:15:55, 2.00
2014-04-29 08:16:02, 3.00
2014-04-29 08:16:10, 4.00
2014-04-29 08:19:31, 6.00

The simple template call it templ.tex (this has to be optimized to fit to your data):

\documentclass[12pt]{article}
\usepackage{bardiag}
\begin{document}

\bardiagrambegin{9.5}{20}{20cm}{1}{2}{1cm}{0.5cm}

And a small script:

#!/bin/bash
IFS="
"
cat templ.tex > new.tex
for line in `cat time.log`;do
    echo ${line} | sed -e 's/\(.*\),\s*\(.*\)/\\baritem\{\1\}\{\2\}{blue}/' >> new.tex
done
printf "\\\bardiagramend{}{}\n\\\end{document}" >> new.tex    
latex new.tex
0

Sometime ago I have similar case. I use gnuplot.

You can use the following example (not tested)

diagram.p

set datafile separator " "
set title "Title"
set xlabel "Data"
set xtics rotate
set xdata time
set timefmt "%Y-%m-%d %H:%M:%s"
set format x "%Y-%m-%d %H:%M:%s"
set ylabel "Count"
set terminal png
set output "diagram.png"
plot ["2014-04-29 08:00":"2014-04-29 09:00"] 'time.log ' using 1:2 title "Diagram" with lines

gnuplot -e "load 'diagram.p'"
1
  • This does not appear to work (tested with Gnuplot 4.4.3 and 4.6) even after fixing the single quotes around the input file name. Besides, the OP asks for a histogram, not a line diagram. Commented Apr 29, 2014 at 9:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .