2014-05-20 4 views
1

누적 막대 그래프를 시간의 흐름에 따라 플롯하고 싶습니다. 이것은 Using gnuplot for stacked histograms과 다른 것으로 밝혀졌습니다.gnuplot을 통해 시간에 따른 누적 막대 그래프

05/11/2014 10:00:00 1 5 1 
05/12/2014 22:00:00 3 5 1 
05/13/2014 13:00:00 4 4 1 
05/14/2014 09:00:00 3 4 1 
05/15/2014 04:00:00 1 2 1 

처음 두 열은 공간으로 분리하고, 나머지 탭으로 구분되어

여기서 데이터이다. X 축은 날짜와 시간이어야합니다.

다음의 gnuplot 스크립트는 문제가있다 :

set title "Test" 
set key invert reverse Left outside 
set key autotitle columnheader 
set style data histogram 
set style histogram rowstacked 
set style fill solid border -1 
set boxwidth 0.75 
set datafile separator '\t' 
set xdata time 
set timefmt '%M/%D/%Y %H:%M:%S' 
set format x '%M/%D %H' 
plot 'test.dat' using 2:xtic(1) title 'Col1', '' using 3 title 'Col2', '' using 4 title 'Col3' 

위의 스크립트 오류가 발생합니다 : X 시간 데이터에 대한 전체 사용 사양이 필요합니다. 그러나 xdata를 설정하지 않으면 작동합니다.

답변

3

set xdata time 부분에서 참으로 잘못된 것입니다 너의 경우. 상자는 등의 정수 x 값 0, 1, 2에 배치되며, 귀하의 경우 첫 번째 열에 포함 된 시간 정보 인 사용자 지정 레이블을 얻을 :

히스토그램 다른 음모를 꾸미고 스타일에서 약간 다른 작동합니다. 따라서 x 축은 실시간 축이 아닙니다.

다음 스크립트는 4.6.4와 함께 잘 작동 : 당신이 라벨에 사용되는 시간 형식을 변경하려는 경우, 수동으로 시간 문자열을 구문 분석합니다

set title "Test" 
set key invert reverse Left outside 
set style data histogram 
set style histogram rowstacked 
set style fill solid border -1 
set boxwidth 0.75 
set datafile separator '\t' 

plot 'test.dat' using 2:xtic(1) title 'Col1', '' using 3 title 'Col2', '' using 4 title 'Col3' 

enter image description here

. xtic(1)xtic(strcol(1))과 같습니다. 난 그냥 원하는 경우 어떻게

set title "Test" 
set key invert reverse Left outside 
set style data histogram 
set style histogram rowstacked 
set style fill solid border -1 
set boxwidth 0.75 
set datafile separator '\t' 

plot 'test.dat' using 2:xtic(strftime('%m/%d %Hh', strptime('%m/%d/%Y %H:%M:%S', strcol(1)))) title 'Col1',\ 
    '' using 3 title 'Col2', '' using 4 title 'Col3' 

enter image description here

1

간단하게 유지하고 큰 따옴표 안에 날짜와 시간 값을 사용하는 것이 어떻습니까?

"05/11/2014 10:00:00" 1 5 1 
"05/12/2014 22:00:00" 3 5 1 
"05/13/2014 13:00:00" 4 4 1 
"05/14/2014 09:00:00" 3 4 1 
"05/15/2014 04:00:00" 1 2 1 

그리고 당신의 음모를 꾸미고 스크립트는 다음과 같습니다 : 그래서 데이터 파일이 될 것

set title "Test" 
set key invert reverse Left outside 
#set key autotitle columnheader 
set style data histogram 
set style histogram rowstacked 
set style fill solid border -1 
set boxwidth 0.75 
set xtics border in scale 0,0 nomirror rotate by 90 offset character 0, -9, 0 
plot 'test.dat' using 2:xtic(1) title 'Col1', '' using 3 title 'Col2', '' using 4 title 'Col3' 

그리고 결과 플롯은 다음과 같습니다

enter image description here

+0

대신 문자열로 첫 번째 열에 정보를 포함 strcol(1)를 사용하여, 당신은 표시된 시간 정보를 변경하기 위해 strptimestrftime이 데이터를 처리 할 수 x 축의 날짜 + 시간을 표시합니다. 예를 들어, set format x '% M/% D % H'? –

+0

이에 따라 데이터 파일을 적절하게 변경할 수 있습니다 : ''05/12/22 : 00 '대신'1 5 1' 05/11/2014 10:00:00 "1 5 1' –

+1

있습니다 모든 필요에 대한 데이터 파일을 변경할 필요가 없습니다;) @erictan 내가 대답을 지적했다 : 히스토그램의 경우 x 축의 동작은'set format x'에 의존하지 않는다. 매번 데이터 파일을 변경하지 않고 xticlabels를 변경하는 방법에 대한 내 대답을 참조하십시오. – Christoph