gnuplot 中的自动偏移
Automatic offset in gnuplot
我正在绘制数据文件中的数据,数据的行为是在 x 轴上一段时间后,y 轴开始单调减少并最终变为零(稍后会有一些非常小的波动)。
因此,我想偏移 y 轴,使这些波动清晰可见。为此,我使用 set offsets 0,0,0,0.1
之类的东西。但我实际上已经编写了一个 bash 脚本来为我生成情节。我只需要向它提供数据文件名。所以对于每个图,我不想进入脚本并根据数据手动设置偏移值。
我希望偏移量是由 gnuplot
基于轴上的 bin-size 自动确定的,例如偏移量是 1*bin-size。所以我的命令看起来像:
set offsets 0,0,0,1*$bin_size
有什么办法可以实现吗?
编辑:
这是我正在使用的脚本。
#!/bin/bash
#Requires that the script be in the same directory as the data files
#sed -n '3001,4000p' fish_data_re.dat > fish_data_re_3k_4k.dat : Can be used to extract data from specific range in data file
DATA_FILE_NAME="abc"
DATA_FILE_TYPE="dat"
#Code to generate normalised files
awk 'NR == FNR {if(max < ) {max = }; next} { = / max; printf "%f\t%f\n", , }' $DATA_FILE_NAME.$DATA_FILE_TYPE $DATA_FILE_NAME.$DATA_FILE_TYPE > $DATA_FILE_NAME\_normed.$DATA_FILE_TYPE
DATA_FILE_NAME="$DATA_FILE_NAME\_normed"
DATA_FILE_TYPE="dat"
OUTPUT_FILE_TYPE="eps"
OUTPUT_FILE_NAME="$DATA_FILE_NAME\_plot.$OUTPUT_FILE_TYPE"
X_LABEL="Time"
Y_LABEL="Real Classical Fisher Information"
TITLE="Real Classical Fisher Information vs Time"
#Set font size for axis tics
X_TICS_SIZE="6"
Y_TICS_SIZE="6"
gnuplot <<- MULTI_LINE_CODE_TAG
set xlabel "$X_LABEL"
set ylabel "$Y_LABEL"
#Following command allows the printing of underscore from name of data file in plot
set key noenhanced
set title "$TITLE"
set xtics font ", $X_TICS_SIZE"
set ytics font ", $Y_TICS_SIZE"
set xtics nomirror
set ytics nomirror
#set ytics format "%.22g"
set ytics format "%0.s*10^{%L}"
#set xtics format "%t"
set multiplot
#------The big-plot------
set title "$TITLE"
set offsets 0,0,0,0.01
#Following plots only data from line 1 to line 100
#plot "<(sed -n '1,100p' $DATA_FILE_NAME.$DATA_FILE_TYPE)" u 1:2 notitle w l lc "red" lw 2
plot "$DATA_FILE_NAME.$DATA_FILE_TYPE" u 1:2 notitle w l lc "red" lw 2
#------The sub-plot------
unset title
unset offsets
set origin 0.25,0.3
set size 0.45,0.45
set xrange [30:60]
set yrange [-0.01:0.01]
unset xlabel
unset ylabel
#unset label
plot "$DATA_FILE_NAME.$DATA_FILE_TYPE" u 1:2 notitle w l lc "red" lw 2
unset multiplot
set term "$OUTPUT_FILE_TYPE"
set output "$OUTPUT_FILE_NAME"
replot
MULTI_LINE_CODE_TAG
exit
如您所见,我需要手动提供偏移量。
这是我得到的情节。
这里的 y 轴偏移了 -0.002 -0.2。我想自动化这件事并希望 gnuplot
始终使用偏移量作为 bin 的大小(我将其定义为连续抽动之间的距离)。
(如果这是一个微不足道的问题,我提前道歉,我对 gnuplot 还很陌生。)
我想我还是不明白你的确切问题。顺便说一下,你的偏移量是 -200e-3 = -0.2 而不是 -0.002。
你的数据总是在 0 和 1 之间吗?
您可以根据图表设置偏移量(检查 help offsets
)
set offsets 0,0,0, graph 0.2
一般来说,为什么不使用对数刻度呢?有了这个,您将能够看到数据中的所有小特征。
代码:
### linear scale vs logarithmic scale
reset session
# Gauss curve by specifing Amplitude A, position x0 and width via FWHM
GaussW(x,x0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))
# create some test data
set xrange[0:100]
set samples 500
set table $Data
plot '+' u 1:(GaussW(,5,1,2.5) + GaussW(,40,7e-3,2) + GaussW(,47,8e-4,5) + 2e-4) w table
unset table
set multiplot layout 1,2
set offset 0,0,0, graph 0.2
set yrange[-0.02:1]
plot $Data u 1:2 w l title "linear y-scale"
set logscale y
set yrange[1e-4:1]
plot $Data u 1:2 w l title "logarithmic y-scale"
unset multiplot
### end of code
结果:
我正在绘制数据文件中的数据,数据的行为是在 x 轴上一段时间后,y 轴开始单调减少并最终变为零(稍后会有一些非常小的波动)。
因此,我想偏移 y 轴,使这些波动清晰可见。为此,我使用 set offsets 0,0,0,0.1
之类的东西。但我实际上已经编写了一个 bash 脚本来为我生成情节。我只需要向它提供数据文件名。所以对于每个图,我不想进入脚本并根据数据手动设置偏移值。
我希望偏移量是由 gnuplot
基于轴上的 bin-size 自动确定的,例如偏移量是 1*bin-size。所以我的命令看起来像:
set offsets 0,0,0,1*$bin_size
有什么办法可以实现吗?
编辑:
这是我正在使用的脚本。
#!/bin/bash
#Requires that the script be in the same directory as the data files
#sed -n '3001,4000p' fish_data_re.dat > fish_data_re_3k_4k.dat : Can be used to extract data from specific range in data file
DATA_FILE_NAME="abc"
DATA_FILE_TYPE="dat"
#Code to generate normalised files
awk 'NR == FNR {if(max < ) {max = }; next} { = / max; printf "%f\t%f\n", , }' $DATA_FILE_NAME.$DATA_FILE_TYPE $DATA_FILE_NAME.$DATA_FILE_TYPE > $DATA_FILE_NAME\_normed.$DATA_FILE_TYPE
DATA_FILE_NAME="$DATA_FILE_NAME\_normed"
DATA_FILE_TYPE="dat"
OUTPUT_FILE_TYPE="eps"
OUTPUT_FILE_NAME="$DATA_FILE_NAME\_plot.$OUTPUT_FILE_TYPE"
X_LABEL="Time"
Y_LABEL="Real Classical Fisher Information"
TITLE="Real Classical Fisher Information vs Time"
#Set font size for axis tics
X_TICS_SIZE="6"
Y_TICS_SIZE="6"
gnuplot <<- MULTI_LINE_CODE_TAG
set xlabel "$X_LABEL"
set ylabel "$Y_LABEL"
#Following command allows the printing of underscore from name of data file in plot
set key noenhanced
set title "$TITLE"
set xtics font ", $X_TICS_SIZE"
set ytics font ", $Y_TICS_SIZE"
set xtics nomirror
set ytics nomirror
#set ytics format "%.22g"
set ytics format "%0.s*10^{%L}"
#set xtics format "%t"
set multiplot
#------The big-plot------
set title "$TITLE"
set offsets 0,0,0,0.01
#Following plots only data from line 1 to line 100
#plot "<(sed -n '1,100p' $DATA_FILE_NAME.$DATA_FILE_TYPE)" u 1:2 notitle w l lc "red" lw 2
plot "$DATA_FILE_NAME.$DATA_FILE_TYPE" u 1:2 notitle w l lc "red" lw 2
#------The sub-plot------
unset title
unset offsets
set origin 0.25,0.3
set size 0.45,0.45
set xrange [30:60]
set yrange [-0.01:0.01]
unset xlabel
unset ylabel
#unset label
plot "$DATA_FILE_NAME.$DATA_FILE_TYPE" u 1:2 notitle w l lc "red" lw 2
unset multiplot
set term "$OUTPUT_FILE_TYPE"
set output "$OUTPUT_FILE_NAME"
replot
MULTI_LINE_CODE_TAG
exit
如您所见,我需要手动提供偏移量。
这是我得到的情节。
-0.002 -0.2。我想自动化这件事并希望 gnuplot
始终使用偏移量作为 bin 的大小(我将其定义为连续抽动之间的距离)。
(如果这是一个微不足道的问题,我提前道歉,我对 gnuplot 还很陌生。)
我想我还是不明白你的确切问题。顺便说一下,你的偏移量是 -200e-3 = -0.2 而不是 -0.002。
你的数据总是在 0 和 1 之间吗?
您可以根据图表设置偏移量(检查 help offsets
)
set offsets 0,0,0, graph 0.2
一般来说,为什么不使用对数刻度呢?有了这个,您将能够看到数据中的所有小特征。
代码:
### linear scale vs logarithmic scale
reset session
# Gauss curve by specifing Amplitude A, position x0 and width via FWHM
GaussW(x,x0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))
# create some test data
set xrange[0:100]
set samples 500
set table $Data
plot '+' u 1:(GaussW(,5,1,2.5) + GaussW(,40,7e-3,2) + GaussW(,47,8e-4,5) + 2e-4) w table
unset table
set multiplot layout 1,2
set offset 0,0,0, graph 0.2
set yrange[-0.02:1]
plot $Data u 1:2 w l title "linear y-scale"
set logscale y
set yrange[1e-4:1]
plot $Data u 1:2 w l title "logarithmic y-scale"
unset multiplot
### end of code
结果: