All y points undefined on gnuplot

Why, when I do this gnuplot code, it works:

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) 

but when I change plot sin(x) to:

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

I have this error:

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

I have only one column! he represents yrange . xrange is represented by the number of lines! example of my datapoint:

 125456 130000 150000 

the first point x is 1, the second point x is 2, and the last is 3. Now I want to represent this 1, 2, 3 with a scale of 50, 55, 60!

+7
source share
1 answer

There are a few things that may be wrong here - it is impossible to say without looking at your data file. A couple that I can come up with with my head says:

All of your datapoints in column 2 are all less than or equal to 0 (you get an error because log (0) is undefined)

You have no points in the first column between 50 and 100. In this case, all your data points are cut out of the graph range due to set xrange [50:100]

There is only one column in your data file ... In this case, gnuplot does not see any y-values. (change to plot '../myFile.final' u 1 ... )

EDIT

Ok, now that I see your data file, the problem is that you have set xrange [50:60] , but your xrange data only works from 0 to 2 (gnuplot starts indexing the data file from 0). The easiest way to fix this is to use the pseudo-column 0. The pseudo-column 0 is just the line number starting with 0 (this is what gnuplot displays on the x axis if you do plot 'blah.txt' using 1 Here is 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: if you do not know how the usage specification works, the numbers preceded by $ are elementary operations for the entire column. For example:

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

builds the first column plus the sum of the second and third elements in each row of the data file.

This solution assumes that you know the maximum x value in your data file (in this case 3-1 = 2 - [three points, 0,1,2]). If you do not know the number of data points, you can get this using the shell shell or directly from gnuplot. The first method is a bit simpler, although not as portable. I will 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" 

Secondly, we need to make two passes through the data and let gnuplot choose 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" 

I suppose, for completeness, I have to say that this is also easier to do in gnuplot 4.6 (I don't have one now, so this next part only 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 looks pretty cool. I'll probably start with him pretty quickly.

+16
source

All Articles