3

私はこのファイルを次のように持っていますdata.dat

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)。

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

そして呼び出すことによって:

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

この画像は生成されます: 画像hist-v1.png

ただし、X軸は数値でスケーリングされていないことに注意してください。これは、X値をカテゴリとして理解します(つまり、カテゴリ軸です)。

次のスクリプトを使用して、より数値のX軸を取得できますhist-v2.gplot(を使用with boxes)。

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ますか?このスレッド「Re:x軸の日付エラーのあるヒストグラム」では、次のことはできません。

しかし、データファイルからx座標の日付を引き出​​すのは難しいでしょう...

しかし、それは別の問題を指します...

ありがとう、

乾杯!

4

2 に答える 2

2

わかりました。ヘルプを少し読んだ後、gnuplotヒストグラムスタイルは「常に」x軸を連続したエントリ/カテゴリとして解釈するようです。したがって、実際、ヒストグラムスタイルで数値軸を取得する方法はないようです。

ただし、これは$列を参照できることがわかり、2番目の(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

...これは私が最初に望んでいたこととほぼ同じです。

ちょっとしたメモ-私はもともとインラインデータでスクリプトを使用したかったのです。このような設定の場合、次のように記述する必要があります。

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

...つまり、データはstdinから入力されるため、複数回入力する必要があります。この問題はgnuplotで説明されています。組み込みのコマンドを使用して、データファイルから複数のプロットを実行します

乾杯!

PS:ダイアグラムにはかなりのスペースがあるので、どういうわけか別々のx軸範囲を指定できればいいのですが。それはで議論されています:

于 2010-08-07T23:14:27.010 に答える
1

「ボックス」プロットスタイルを使用してヒストグラムをプロットする場合、ボックス幅を適切に設定することは非常に重要です。私のブログ記事の1つで、私はそれについて話しました。興味のある方はこちらをクリック!

ここに画像の説明を入力してください

于 2011-09-17T11:25:26.210 に答える