未定义变量:GPVAL_DATA_Y_MIN(Gnuplot)
基于这篇文章(我使用的是gnuplot gnuplot 4.6 patchlevel 1): 我正试图在我的.pg脚本中使用未定义变量:GPVAL_DATA_Y_MIN(Gnuplot),gnuplot,Gnuplot,基于这篇文章(我使用的是gnuplot gnuplot 4.6 patchlevel 1): 我正试图在我的.pg脚本中使用set yr[GPVAL\u DATA\u Y\u MIN:GPVAL\u DATA\u Y\u MAX],该脚本打印此.dat文件中的数据: 100 2 200 4 300 9 但我得到: undefined variable: GPVAL_DATA_Y_MIN 这是我的剧本: set terminal png set output 'img.png' set xl
set yr[GPVAL\u DATA\u Y\u MIN:GPVAL\u DATA\u Y\u MAX]
,该脚本打印此.dat文件中的数据:
100 2
200 4
300 9
但我得到:
undefined variable: GPVAL_DATA_Y_MIN
这是我的剧本:
set terminal png
set output 'img.png'
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5
set style fill solid
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
plot 'sample.dat' with boxes title ""
有什么想法吗?gnuplot定义的变量只有在执行
plot
命令后才可用(在您链接的问题中,使用replot
再次绘图)
基本上你有不同的选择:
unknown
,然后更改到实际终端,设置范围(现在变量可用),然后replot
:
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5 relative
set style fill solid
set terminal unknown
plot 'sample.dat' with boxes title ""
set terminal pngcairo
set output 'img.png'
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
注意,我使用了pngcairo
终端,它比png
终端提供了更好的结果。我使用了将boxwidth设置为0.5 relative
set autoscale
固定范围,而不是设置显式yrange
。您可以使用set offset
根据自动缩放的值指定边距:
set autoscale yfix
# set offset 0,0,0.5,0.5
plot 'sample.dat' with boxes title ''
stats
命令提取最小值和最大值:
stats 'sample.dat' using 1:2
set yrange[STATS_min_y:STATS_max_y]
plot 'sample.dat' with boxes title ''