所有点y值在gnuplot上未定义 [英] All points y value undefined on gnuplot

查看:199
本文介绍了所有点y值在gnuplot上未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么当我使gnuplot的代码起作用时:

Why when i make this code of gnuplot it's work :

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

我只有一栏!它代表yrange. xrange由行号表示!我的数据点示例:

I have juste one column ! it represente yrange. xrange is represented by number of line ! example of my datapoint :

125456
130000
150000

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

first point of x is 1, second point of x is 2, and last is 3. now i want to represente this 1, 2, 3 by a scale 50, 55, 60 !

推荐答案

这里有些事情可能会出错-看不到您的数据文件是无法分辨的.我能想到的一对夫妇是:

There are a few things which could be going wrong here -- without seeing your datafile it is impossible to tell. A couple which I can think of off the top of my head are:

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

All your datapoints in column 2 are all less than or equal to 0 (You get the error message because log(0) is undefined)

第一列中的50至100之间没有任何点.在这种情况下,由于set xrange [50:100]

You don't have any points in the first column between 50 and 100. In this case, all your datapoints get clipped out of the plot range because of set xrange [50:100]

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

Your datafile only has 1 column...In this case, gnuplot doesn't see any y-values. (change to plot '../myFile.final' u 1 ...)

编辑

好吧,现在我看到了您的数据文件,问题肯定是您已经set xrange [50:60]了,但是数据的xrange仅从0到2运行(gnuplot从0开始对数据文件建立索引).解决此问题的最简单方法是使用伪列0.伪列0只是从0开始的行号(如果执行plot 'blah.txt' using 1,这是gnuplot在x轴上的绘制.这是示例:

Ok, now that I see your datafile, the problem is definitely that you've set xrange [50:60] but your data's xrange only runs from 0 to 2 (gnuplot starts datafile indexing from 0). The easiest way to fix this is to use the pseudo-column 0. Pseudo-column 0 is simply the line number starting from 0 (which is what gnuplot plots on the x axis if you do plot 'blah.txt' using 1. Here's an example:

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"

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

Note that if you don't know how the using specification works, numbers preceded by $ are element-wise operations on that whole column. For example:

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

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

will plot the first column plus the sum of the 2nd and third elements in each row of the datafile.

此解决方案假定您知道数据文件中x的最大值(在这种情况下,为3-1 = 2-[3分,0,1,2]).如果您不知道数据点的数量,则可以使用Shell Magic或直接从gnuplot获得.第一种方法虽然不那么便携,但比较容易.我将同时显示:

This solution assumes that you know the maximum value of x in your datafile (in this case, that's 3-1=2 -- [three points, 0,1,2]). If you don't know the number of datapoints, you can get that using shell magic, or directly from gnuplot. The first way is a little easier, although not as portable. I'll show both:

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获取最大值:

The second way, we need to make two passes through the data and let gnuplot pick up the maximum:

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中也更容易做到(我现在还没有安装它,所以下一部分仅来自我对文档的理解):

I suppose for completeness, I should say that this is also easier to do in gnuplot 4.6 (I don't have it installed right now, so this next part just comes from my understanding of the docs):

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看起来很酷.我可能很快就会开始使用它.

Gnuplot 4.6 looks pretty cool. I'll probably start playing around with it pretty soon.

这篇关于所有点y值在gnuplot上未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆