2010-08-07 5 views
3

내가 data.dat으로이 파일을 보내고 있습니다 :gnuplot에서 숫자가있는 x 축이있는 막대 그래프?

set xlabel "X values" 
set ylabel "Occurence" 
set style data histogram 
set style histogram cluster gap 1 
set style fill solid border -1 
set term png 
set output 'hist-v1.png' 
set boxwidth 0.9 
# attempt to set xtics so they are positioned numerically on x axis: 
set xtics ("332" 332, "336" 336, "340" 340, "394" 394, "398" 398, "1036" 1036) 
# ti col reads the first entry of the column, uses it as title name 
plot 'data.dat' using 2:xtic(1) ti col, '' u 3 ti col, '' u 4 ti col, '' u 5 ti col 

을 그리고 호출하여 : :이 스크립트를 히스토그램으로이 데이터를 플롯 할 수 있습니다

Xstep Y1 Y2 Y3 Y4 
332 1.22 0.00 0.00 1.43 
336 5.95 12.03 6.11 10.41 
340 81.05 81.82 81.92 81.05 
394 11.76 6.16 10.46 5.87 
398 0.00 0.00 1.51 1.25 
1036 0.03 0.00 0.00 0.00 

hist-v1.gplot은 (set style data histogram 사용)

gnuplot hist-v1.gplot && eog hist-v1.png 

이 이미지가 생성됩니다. image hist-v1.png http://img202.imageshack.us/img202/3974/histv1.png

그러나 X 축의 수치가 비례하지 않음을 알 수 있습니다. 범주 축입니다).

내가 hist-v2.gplot이 (with boxes를 사용하여) 다음과 같은 스크립트를 더 숫자 X 축를 얻을 수 있습니다 :

set xlabel "X values" 
set ylabel "Occurence" 
# in this case, histogram commands have no effect 
set style data histogram 
set style histogram cluster gap 1 
set style fill solid border -1 
set term png 
set output 'hist-v2.png' 
set boxwidth 0.9 
set xr [330:400] 
# here, setting xtics makes them positioned numerically on x axis: 
set xtics ("332" 332, "336" 336, "340" 340, "394" 394, "398" 398, "1036" 1036) 
# 1:2 will ONLY work with proper xr; since we have x>300; xr[0:10] generates "points y value undefined"! 
plot 'data.dat' using 1:2 ti col smooth frequency with boxes, '' u 1:3 ti col smooth frequency with boxes 

그리고에 의해

호출 :

gnuplot hist-v2.gplot && eog hist-v2.png 

이 이미지가 생성됩니다 image hist-v2.png http://img266.imageshack.us/img266/6717/histv2.png

불행히도 막대 그래프가 여기에서 겹쳐서 그래프를 읽는 것이 어렵습니다.

숫자 축척 X 축을 hist-v2.png으로 유지하는 방법이 있습니까? hist-v1.png과 같이 '막대'를 나란히 배치 하시겠습니까?

하지만, 데이터 파일의 밖으로 x 좌표 날짜를 당겨 힘들 것입니다 ...

하지만, 그것은을 의미 :이 스레드는 "Re: Histogram with x axis date error가"라고 당신은 할 수 없습니다 다른 문제 ...

감사합니다,

건배!

답변

2

좋아, 도움말을 읽은 후 히스토그램 스타일은 항상 x 축을 순차적 인 항목/범주로 해석합니다. - 실제로 숫자 축을 얻을 수있는 방법이 없을 것 같습니다. 히스토그램 스타일.

그러나 $은 열을 참조 할 수 있으며 두 번째 열 (frequency with boxes 스타일)의 예에서 막대를 실제로 '재배치'하는 데 사용될 수 있습니다. 그래서 hist-v2b.gplot로이 코드 :

set xlabel "X values" 
set ylabel "Occurence" 
set style fill solid border -1 
set term png 
set output 'hist-v2.png' 
set boxwidth 0.9 
set xr [330:400] 
# here, setting xtics makes them positioned numerically on x axis: 
set xtics ("332" 332, "336" 336, "340" 340, "394" 394, "398" 398, "1036" 1036) 
# 1:2 will ONLY work with proper xr; since we have x>300; xr[0:10] generates "points y value undefined"! 
plot 'data.dat' using ($1-0.5):2 ti col smooth frequency with boxes, '' u ($1-0.25):3 ti col smooth frequency with boxes, '' u ($1+0.25):4 ti col smooth frequency with boxes, '' u ($1+0.5):5 ti col smooth frequency with boxes 

그리고 호출하여 :

gnuplot hist-v2b.gplot && eog hist-v2b.png 

이 이미지가 생성됩니다 꽤 많이 나는 처음에 원했던 것입니다 image hist-v2b.png http://img823.imageshack.us/img823/805/histv2b.png

을 ... .

작은 메모 - 처음에는 인라인 데이터가있는 스크립트를 사용하고 싶었습니다. 이 문제가 gnuplot - do multiple plots from data file with built-in commands에 설명되어 있습니다 -이 같은 설정의 경우, 데이터는 표준 입력에서 온다, 여러 번 입력해야 할 것입니다 ... 즉,

plot '-' using ($1-0.5):2 ti col smooth frequency with boxes, '-' u ($1-0.25):3 ti col smooth frequency with boxes 
Xstep Y1 Y2 Y3 Y4 
332 1.22 0.00 0.00 1.43 
336 5.95 12.03 6.11 10.41 
340 81.05 81.82 81.92 81.05 
394 11.76 6.16 10.46 5.87 
398 0.00 0.00 1.51 1.25 
1036 0.03 0.00 0.00 0.00 
end 
Xstep Y1 Y2 Y3 Y4 
332 1.22 0.00 0.00 1.43 
336 5.95 12.03 6.11 10.41 
340 81.05 81.82 81.92 81.05 
394 11.76 6.16 10.46 5.87 
398 0.00 0.00 1.51 1.25 
1036 0.03 0.00 0.00 0.00 
end 

로 작성되어야한다.

건배!

추신 : 다이어그램에 꽤 많은 공간이 있으므로 별도의 x 축 범위를 지정할 수 있다면 좋을 것입니다. 그이 설명되어 있습니다 : 당신이 "상자"플롯 스타일을 사용하여 히스토그램을 그릴 때

1

상자 폭 설정이 제대로 매우 중요합니다. 내 블로그 기사 중 하나에서 나는 그것에 대해 이야기했다. 관심이 있으시면 here을 클릭하십시오. 환호 - 솔루션, @hsxz을 게시

enter image description here

+0

많은 감사합니다! – sdaau