3

非常に大きなデータセットの場合、gnuplot を使用して、最初と最後のデータ ポイントだけに目盛り/ラベルを x 軸にのみ配置するにはどうすればよいですか?

4

2 に答える 2

4

gnuplot 4.6 以降では、次のコマンドを使用できます。

stats 'data.dat'
set xtics \
 (sprintf("%.2g",STATS_min_x) STATS_min_x, \
  sprintf("%.2g",STATS_max_x) STATS_max_x)
plot 'data.dat'

gnuplot の他のバージョンでは、次のような一連のコマンドを使用できます。

# this setting makes sure we don't make an output right away
set terminal unknown
plot 'data.dat'
set xtics \
 (sprintf("%.2g",GPVAL_DATA_X_MIN) GPVAL_DATA_X_MIN, \
  sprintf("%.2g",GPVAL_DATA_X_MAX) GPVAL_DATA_X_MAX)
set terminal <actual terminal>
replot

このset xticsコマンドは、カンマで区切られた文字列とデータ値のペアをすべて括弧内に取ります。

(ここでは、最初と最後のデータ ポイントではなく、最小値と最大値が必要であると想定しています。)

詳細については、gnuplot コマンド ラインでこれらを実行できます。

help set format

help set stats

show variables all

于 2013-01-02T21:47:49.160 に答える
0

別の回答が実際に別の質問に回答したため、別の回答を追加していますが、役立つ場合があります。質問に答えるには、

最初と最後のデータ ポイントの x 目盛りをマークする方法は?

ここに私の方法があります:

#!/usr/bin/env gnuplot

set terminal png
set output 'test.png'

# define a function to get the first and last values.
# this assumes the file has not changed since first running 'stats',
# (and contains at least one data point)
# `plot/stats 'data.dat' using (firstlast($x))`
# should be interchangable with
# `plot/stats 'data.dat' using x
# that is, the resulting variables should be the same
firstlast(x) = ($0==0) ? (first=$1, last=$1, $1) : (last=$1, $1)

# run stats  to find the first and last values
# just on x data column
stats 'data.dat' u (firstlast($1)) nooutput

# set the x tics to the first and last x points
set xtics \
 (sprintf("%.2g (first)", first) first, \
  sprintf("%.2g (last)", last) last)

print first
print last

plot 'data.dat'

このサンプル データ ファイルを使用しました。

データ.dat

1 1
2 2
3 3
4 2
0 3

そして、この出力を得ました:

ここに画像の説明を入力

于 2013-01-02T22:47:10.690 に答える