Gnuplot-Like Program for Timeline Data

gnuplot-like program for timeline data

Along with R there is also matplotlib that has tons of charting possibilities.

Also I prefer matplotlib because it builds on python which is a very well developed and documented scripting language.

If you have used matlab before you will find matplotlib very easy to learn since it orients its API after the matlab way of plotting stuff.

How to plot data with lines like text datetime, with gnuplot?

I guess what you want is something like this Sample Image

The x-axis spans the time interval which is specified by your data file (2nd column). Each name (Ken, Mom, Dad) is represented by a different point type (pt) and a specific colour (lc rgb 'color').

You can generate this plot by the following commands (assuming your data file's name is 'test'):

set xdata time
set timefmt "%s"
set format x "%d/%m/%y"
set xtics rotate
unset ytics
set yrange[0:2]

plot 'test' u ($2):(stringcolumn(1) eq "Ken" ? 1 :1/0) w p pt 5 ps 1.5 lc rgb 'blue' t 'Ken',\
'' u ($2):(stringcolumn(1) eq "Dad" ? 1 :1/0) w p pt 7 ps 1.5 lc rgb 'red' t 'Dad',\
'' u ($2):(stringcolumn(1) eq "Mom" ? 1 :1/0) w p pt 3 ps 1.5 lc rgb 'green' t 'Mom'

You can use different point types by assigning different numbers to pt. ps specifies the point size.

Another representation I came up with is the following:Sample Image
You can generate it with:

plot 'test' u ($2):(1):(stringcolumn(1)) with labels t '',\
'' u ($2):(0.95) with impulses t ''

I hope this answers your question, and it is what you were looking for.

plotting sequence in timeline

How about something like this:

sum=0
cum_sum(x)=(sum=sum+x,sum-x/2)
set yrange [-1:2]
set xrange [0:*]
unset ytics
set style fill solid
plot 'test.dat' using (cum_sum($2)):(1.0):($2):($0) w boxes t "execution" lc variable

and here's a version which colors the boxes based on the label (I have to admit, I'm pretty proud of this hack):

sum=0
cum_sum(x)=(sum=sum+x,sum-x/2)
set yrange [-1:2]
set xrange [0:*]
unset ytics
set style fill solid
LABELS="ABCD"
plot 'test.dat' using (cum_sum($2)):(1.0):($2):(strstrt(LABELS,strcol(1))) w boxes t "execution" lc variable

If you want to control which color a particular label gets, you'd want to use set style line X lc rgb 'cyan' where the label which starts at index X in the LABELS string will be colored cyan.

Stacked histogram with time series data with gnuplot?

Combine data for each day using smooth freq and a bin() function that rounds epoch times to days. Plot sums of the y-axis categories as boxes in descending order of height using inline for and a sum expression so the differences between sums equal the values of the categories. So, the tallest box will have height foo+bar+baz (caller=3), the next tallest foo+bar (caller=2), and the shortest is just foo (caller=1).

calls:

caller  method      call_count  day
foo find_paths 10 2016-10-10
bar find_paths 100 2016-10-10
foo find_all 123 2016-10-10
foo list_paths 2243 2016-10-10
foo find_paths 234 2016-10-11
foo collect 200 2016-10-11
bar collect 1 2016-10-11
baz collect 3 2016-10-11

gnuplot script:

binwidth = 86400
bin(t) = (t - (int(t) % binwidth))
date_fmt = "%Y-%m-%d"
time = '(bin(timecolumn(4, date_fmt)))'

# Set absolute boxwidth so all boxes get plotted fully. Otherwise boxes at the
# edges of the range can get partially cut off, which I think looks weird.
set boxwidth 3*binwidth/4 absolute

set key rmargin
set xdata time
set xtics binwidth format date_fmt time rotate by -45 out nomirror
set style fill solid border lc rgb "black"

callers = system("awk 'NR != 1 {print $1}' calls \
| sort | uniq -c | sort -nr | awk '{print $2}'")
# Or, if Unix tools aren't available:
# callers = "foo bar baz"

plot for [caller=words(callers):1:-1] 'calls' \
u @time:(sum [i=1:caller] \
strcol("caller") eq word(callers, i) ? column("call_count") : 0) \
smooth freq w boxes t word(callers, caller)

Calls per day, by caller

I wrote a longer discussion about gnuplot time-series histograms here: Time-series histograms: gnuplot vs matplotlib

Aligning values with timestamps to a timeline

The conventional, simple part is plotting of the actual data. For this you can use the labels plotting style. A very simple example would be:

set xtics (0)
set xrange [0:*]
set offsets graph 0, graph 0.2, graph 0.2, graph 0.2
set style data labels
unset key
plot 'O1.dat' using 1:(5):(gprintf('%g', $2)):ytic('O1'),\
'O2.dat' using 1:(4):(gprintf('%g', $2)):ytic('O2'),\
'Avg.dat' using 1:(3):(gprintf('%g', $2)):ytic('Avg'):xtic(1)

That simply plots the values from your data files as labels at the x-positions given in the first columns. The y-positions are set as fixed numbers:

Sample Image

In order to move the xtick labels to the top and have some table-like lines you need a bit more tweaking:

reset

set termoption font ",20"
set label 'Object' at graph 0, graph 1 offset -1, char 1 right
unset border
unset key
unset xtics
set ytics scale 0
set x2tics () scale 0 format "%g"
set yrange [2:5.5]
set x2range[0:*]
set lmargin 8

set arrow from graph -0.15, graph 1 to graph 1.1, graph 1 nohead
set arrow from graph 0, graph 1.2 to graph 0, graph 0 nohead
set arrow from graph -0.15, first 3.25 to graph 1.1, first 3.25 nohead

set style data labels
plot 'O1.dat' using 1:(5):(sprintf('%d', $2)):ytic('O1') axes x2y1,\
'O2.dat' using 1:(4):(sprintf('%d', $2)):ytic('O2') axes x2y1,\
'Avg.dat' using 1:(2.5):(gprintf('%g', $2)):ytic('Avg'):x2tic(1) axes x2y1

Such a table layout isn't a typical task, so you must adapt several settings to your final result. Main impact comes from canvas size, font and, font size.

Sample Image

If you have more than those two files you could of course also iterate over a file list.



Related Topics



Leave a reply



Submit