【问题标题】:Stacked histogram with time series data with gnuplot?带有gnuplot的时间序列数据的堆叠直方图?
【发布时间】:2017-06-22 00:12:13
【问题描述】:

我有很多这样的数据

 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 语句,例如'Need full using spec for x time data' 等。

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

感谢您的任何想法

【问题讨论】:

标签: charts gnuplot histogram bar-chart stackedbarseries


【解决方案1】:

使用smooth freqbin() 函数组合每一天的数据,该函数将纪元时间舍入到天。使用内联for 和求和表达式将 y 轴类别的总和绘制为框,以使总和之间的差异等于类别的值。所以,最高的盒子有高度 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 时间序列直方图的更长的讨论:Time-series histograms: gnuplot vs matplotlib

【讨论】:

  • 很好,我要试试这个
猜你喜欢
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
  • 2016-10-27
  • 1970-01-01
  • 2012-06-04
  • 1970-01-01
  • 2016-04-28
  • 1970-01-01
相关资源
最近更新 更多