基于这篇文章(我正在使用gnuplot gnuplot 4.6 patchlevel 1):
我试图set yr [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]在我的.pg脚本中使用,该脚本绘制来自此.dat文件的数据:
100 2
200 4
300 9
Run Code Online (Sandbox Code Playgroud)
但我得到:
undefined variable: GPVAL_DATA_Y_MIN
Run Code Online (Sandbox Code Playgroud)
这是我的脚本:
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 ""
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
gnuplot定义的变量仅在plot命令后可用(在您链接的问题中,a 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
Run Code Online (Sandbox Code Playgroud)
注意,我使用了pngcairo终端,它比png终端提供了更好的结果.我用过set 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 ''
Run Code Online (Sandbox Code Playgroud)使用该stats命令提取最小值和最大值:
stats 'sample.dat' using 1:2
set yrange[STATS_min_y:STATS_max_y]
plot 'sample.dat' with boxes title ''
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
4456 次 |
| 最近记录: |