问题
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:
First plot to terminal
unknown
, and then change to the real terminal, set the range (now the variables are available), andreplot
: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 thepng
terminal. And I usedset boxwidth 0.5 relative
.Use
set autoscale
to fix the ranges instead of setting an explicityrange
. You can useset 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 ''
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