2

我有很多这样的数据

 callr |    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
 ...      ...             ...        ...

我想为每种方法创建一个堆叠直方图,显示底部的连续天数和每天的堆叠条形图,其中包含调用者和调用次数。

如果我转换数据,例如

select method, sum(call_count), day from foo where method='collect' group by method, day order by method, day;

我可以获得一个条形图,其中包含一种颜色的一种方法的所有调用,带有这样的 plg 文件,例如:

set terminal png
set title "Method: " . first_arg
set output "" . first_arg . ".png"
set datafile separator '|'
set style data boxes
set style fill solid
set boxwidth 0.5
set xdata time
set timefmt "%Y-%m-%d"
set format x "%a %m-%d"
xstart="2016-10-01"
xend="2017-01-01"
set xrange [xstart:xend]
set xlabel "Date" tc ls 8  offset -35, -3
set ylabel "Calls"  tc ls 8

plot '<cat' using 3:4

像这样调用:

cat file | gnuplot -p -e "plot '<cat';first_arg='collect'" calls.plg

所有调用的直方图

但是,我真正想要的是一种在同一种图表中显示调用者细分的方法。我还无法使用 gnuplot 获得堆叠直方图。我尝试过的所有内容都抱怨 using 语句,例如“需要完全使用 x 时间数据的规范”等。

想要这样的东西,但随着底部的日子连续不断。例如,如果那天没有打电话 - 那么没有直方图条

在此处输入图像描述

谢谢你的任何想法

4

1 回答 1

2

结合每天的数据smooth freq和一个bin()将纪元时间四舍五入到天的函数。使用 inline 和 sum 表达式将 y 轴类别的总和绘制为按高度降序排列的框,以便for总和之间的差异等于类别的值。因此,最高的盒子将有高度 foo+bar+baz ( caller=3),下一个最高的 foo+bar ( caller=2),最短的只是 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 脚本:

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)

呼叫者每天的呼叫次数

我在这里写了一个关于 gnuplot 时间序列直方图的更长的讨论:时间序列直方图:gnuplot vs matplotlib

于 2017-10-11T01:50:40.923 回答