2017-02-04 6 views
2

나는이gnuplot을 사용하여 시계열 데이터가 포함 된 누적 막대 그래프?

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

처럼 많은 데이터를 가지고 있고 발신자와 통화 수와 매일 하단 연속 일 스택 막대를 보여주는 각 방법에 대한 누적 히스토그램을 만들려고합니다.

데이터를 변환하면 (예 :

는 나는이 같은 PLG 파일을 하나의 색으로 하나의 방법에 대한 모든 호출로 막대 그래프를 얻을 수있어
select method, sum(call_count), day from foo where method='collect' group by method, day order by method, day; 

는 예 : 같은

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 

histogram of all calls

그러나, 내가 정말 원하는 것은에서 호출에 의해 붕괴를 보여주는 방법이다 같은 종류의 그래프. gnuplot을 사용하여 누적 막대 그래프를 아직 얻을 수 없습니다. 시도한 모든 내용이 using 문에 대해 불만을 토로합니다. 'x 시간 데이터에 대한 스펙을 사용하여 전체가 필요함'등.

다음과 같은 항목이 필요하지만 하단에 연속 된 일이 있어야합니다. 예 : 더 호출이 그 날하지 않은 경우 - 다음 없음 히스토그램 표시 줄을

enter image description here

+0

는 내가 함께했다 내가 주로하는 R의 해법 happy with http://stackoverflow.com/questions/42049243/ggplot2-histogram-legend-too-large – slashdottir

답변

2

smooth freq를 사용하여 각 하루 일 신기원 시간을 사사 오입 bin() 기능에 대한 데이터를 결합 아이디어 주셔서 감사합니다. 인라인 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) 

Calls per day, by caller

내가의 gnuplot 시계열에 대한 긴 토론을 썼다

여기 히스토그램 : Time-series histograms: gnuplot vs matplotlib

+1

깔끔하게 해보겠습니다. – slashdottir