Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Charts 带gnuplot的时间序列数据的叠加直方图?_Charts_Gnuplot_Histogram_Bar Chart_Stackedbarseries - Fatal编程技术网

Charts 带gnuplot的时间序列数据的叠加直方图?

Charts 带gnuplot的时间序列数据的叠加直方图?,charts,gnuplot,histogram,bar-chart,stackedbarseries,Charts,Gnuplot,Histogram,Bar Chart,Stackedbarseries,我有很多这样的数据 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 |

我有很多这样的数据

 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
设置终端png
设置标题“方法:”。第一个参数
将输出设置为“”。第一个参数。“.png”
设置数据文件分隔符“|”
设置样式数据框
设置样式填充实体
将boxwidth设置为0.5
设置扩展数据时间
设置时间“%Y-%m-%d”
设置格式x“%a%m-%d”
xstart=“2016-10-01”
xend=“2017-01-01”
设置xrange[xstart:xend]
设置xlabel“日期”tc ls 8偏移量-35,-3
设置标签“呼叫”tc ls 8

使用
smooth freq
和一个
bin()
函数将每天的数据组合在一起,该函数将历元时间舍入为天。使用内联
for
和求和表达式,将y轴类别的总和按高度降序绘制为方框,使总和之间的差值等于类别的值。因此,最高的框的高度为foo+bar+baz(
caller=3
),次高的框的高度为foo+bar(
caller=2
),最短的框仅为foo(
caller=1

调用

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时间序列直方图的较长讨论:

我在R中提出了一个解决方案,我对neat非常满意,我要试试这个
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)