未定义变量:GPVAL_DATA_Y_MIN(Gnuplot)

未定义变量: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

基于这篇文章(我使用的是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 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 ''