在gnuplot上,所有点y值都未定义

Meh*_*hdi 8 gnuplot

为什么当我制作这个gnuplot代码时它的工作原理:

set terminal postscript enhanced color
set output '../figs/ins_local.ps'

set title "Result"

set logscale y
set xrange [50:100]
set xtics 5

#set xlabel "Insertion"
#set ylabel "Time (in microseconds) "

plot sin(x)
Run Code Online (Sandbox Code Playgroud)

但是当我改变plot sin(x)时:

plot "../myFile.final" with lines title "Somethings" lw 3  linecolor rgb "#29CC6A"
Run Code Online (Sandbox Code Playgroud)

我有这个错误:

plot "../myFile.final" with lines title "Somethings" lw 3  linecolor rgb "#29CC6A"
                                                                                              ^
"local.gnuplot", line 16: all points y value undefined
Run Code Online (Sandbox Code Playgroud)

我有一个专栏!它代表了yrange.xrange用行数表示!我的数据点的例子:

125456
130000
150000
Run Code Online (Sandbox Code Playgroud)

x的第一个点是1,x的第二个点是2,最后是3.现在我想用比例50,55,60来表示这个1,2,3!

mgi*_*son 21

这里有一些可能出错的事情 - 没有看到你的数据文件是不可能的.我能想到的一对夫妇是:

第2列中的所有数据点都小于或等于0(您收到错误消息,因为未定义log(0))

在50和100之间的第一列中没有任何点.在这种情况下,所有数据点都会从绘图范围中删除,因为 set xrange [50:100]

您的数据文件只有1列...在这种情况下,gnuplot看不到任何y值.(改为plot '../myFile.final' u 1 ...)

编辑

好了,现在我看到你的数据文件,问题肯定是你的,set xrange [50:60]但你的数据的xrange只从0到2运行(gnuplot从0开始数据文件索引).解决这个问题的最简单方法是使用伪列0.伪列0只是从0开始的行号(如果你这样做的话就是gnuplot在x轴上绘制的plot 'blah.txt' using 1.这是一个例子:

scale_x(x,xmin,xmax,datamin,datamax)=xmin+(xmax-xmin)/(datamax-datamin)*x
plot 'test.dat' using (scale_x($0,50,60,0,2)):1 w lines title "scaled xrange"
Run Code Online (Sandbox Code Playgroud)

请注意,如果您不知道使用规范如何工作,则前面带有$的数字是整个列上的按元素操作.例如:

plot 'foo.bar' using 1:($2+$3) 
Run Code Online (Sandbox Code Playgroud)

将绘制第一列以及数据文件每一行中第二和第三个元素的总和.

此解决方案假设您知道数据文件中x的最大值(在这种情况下,即3-1 = 2 - [三点,0,1,2]).如果您不知道数据点的数量,可以使用shell magic或直接从gnuplot获取.第一种方式稍微容易一点,虽然不那么便携.我将展示两者:

XMAX=`wc -l datafile | awk '{print $1-1}'` 
scale_x(x,xmin,xmax,datamin,datamax)=xmin+(xmax-xmin)/(datamax-datamin)*x
plot 'test.dat' using (scale_x($0,50,60,0,XMAX)):1 w lines title "scaled xrange"
Run Code Online (Sandbox Code Playgroud)

第二种方式,我们需要对数据进行两次传递,让gnuplot获取最大值:

set term push  #save terminal settings
set term unknown #use unknown terminal -- doesn't actually make a plot, only collects stats
plot 'test.dat' u 0:1 #collect stats
set term pop   #restore terminal settings
XMIN=GPVAL_X_MIN #should be 0, set during our first plot command
XMAX=GPVAL_X_MAX #should be number of lines-1, collected during first plot command
scale_x(x,xmin,xmax,datamin,datamax)=xmin+(xmax-xmin)/(datamax-datamin)*x
plot 'test.dat' using (scale_x($0,50,60,XMIN,XMAX)):1 w lines title "scaled xrange"
Run Code Online (Sandbox Code Playgroud)

我想为了完整性,我应该说在gnuplot 4.6中也更容易做到(我现在没有安装它,所以下一部分只是来自我对文档的理解):

stats 'test.dat' using 0:1 name "test_stats"
#at this point, your xmin/xmax are stored in the variables "test_stats_x_min"/max
XMIN=test_stats_x_min
XMAX=test_stats_x_max
scale_x(x,xmin,xmax,datamin,datamax)=xmin+(xmax-xmin)/(datamax-datamin)*x
plot 'test.dat' using (scale_x($0,50,60,XMIN,XMAX)):1 w lines title "scaled xrange"
Run Code Online (Sandbox Code Playgroud)

Gnuplot 4.6看起来很酷.我很快就会开始玩它.

  • : 之前的内容是要绘制的 x 值,冒号之后的内容是要绘制的 y 值——在这种情况下,1 表示“选择第一列中的数据”。所以“使用 1:2”意味着从第一列数据中绘制 x 值,从第二列数据中绘制 y 值。`using ($1+$2):2` 表示将前两列的总和绘制为 x 值,将第二列绘制为 y 值。`using 0:1` 表示将行号绘制为 x,将第一列绘制为 y 等。使用 $ 语法,您还可以将值传递给用户定义的函数,就像我上面所做的那样。希望有帮助。 (2认同)