undefined variable: GPVAL_DATA_Y_MIN (Gnuplot)

风流意气都作罢 提交于 2020-01-11 04:01:06

问题


Based on this post (I am using gnuplot gnuplot 4.6 patchlevel 1):

gnuplot: max and min values in a range

I am trying to use set yr [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX] in my .pg script that plots data from this .dat file:

100 2
200 4
300 9

But I get:

undefined variable: GPVAL_DATA_Y_MIN

This is my script:

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 ""

Any ideas?


回答1:


The gnuplot-defined variables are available only after a plot command (In the question you linked to, a replot is used to plot again).

Basically you have different options:

  1. First plot to terminal unknown, and then change to the real terminal, set the range (now the variables are available), and 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
    

    Note, that I used the pngcairo terminal, which gives much better results, than the png terminal. And I used set boxwidth 0.5 relative.

  2. Use set autoscale to fix the ranges instead of setting an explicit yrange. You can use set offset to specify a margin based on the autoscaled values:

    set autoscale yfix
    # set offset 0,0,0.5,0.5
    plot 'sample.dat' with boxes title ''
    
  3. Use the stats command to extract the minimum and maximum values:

    stats 'sample.dat' using 1:2
    set yrange[STATS_min_y:STATS_max_y]
    plot 'sample.dat' with boxes title ''
    


来源:https://stackoverflow.com/questions/19646678/undefined-variable-gpval-data-y-min-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!