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)
but when i change plot sin(x)
with :
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 juste one column ! it represente yrange
. xrange
is represented by number of line ! example of my datapoint :
125456
130000
150000
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:
All your datapoints in column 2 are all less than or equal to 0 (You get the error message because log(0) is undefined)
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]
Your datafile only has 1 column...In this case, gnuplot doesn't see any y-values. (change to plot '../myFile.final' u 1 ...
)
EDIT
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.
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"
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"
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 looks pretty cool. I'll probably start playing around with it pretty soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With