13

为什么当我制作这个 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)

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

plot "../myFile.final" with lines title "Somethings" lw 3  linecolor rgb "#29CC6A"

我有这个错误:

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

我只有一栏!它代表yrangexrange由行数表示!我的数据点示例:

125456
130000
150000

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

4

1 回答 1

25

这里有一些可能出错的地方——没有看到你的数据文件就不可能知道。我能想到的一对是:

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

请注意,如果您不知道 using 规范是如何工作的,则以 $ 开头的数字是对该整列的元素操作。例如:

plot 'foo.bar' using 1:($2+$3) 

将绘制第一列加上数据文件每一行中第二个和第三个元素的总和。

此解决方案假定您知道数据文件中 x 的最大值(在这种情况下,即 3-1=2 -- [三点,0,1,2])。如果您不知道数据点的数量,您可以使用 shell 魔术或直接从 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"

第二种方式,我们需要对数据进行两次传递,让 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"

我想为了完整起见,我应该说这在 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"

Gnuplot 4.6 看起来很酷。我可能很快就会开始玩它。

于 2012-05-30T12:08:29.843 回答