I have a file which has random values between -256 to +256 in a file. Each entry is in a new line. I want to plot this file with the values in the file on the y axis. I do not know the number of entries while executing the plot command. Anybody know any way to do this?
1 Answer
If I understand you correctly, your file looks like this:
100
-120
248
10
-212
...
(I've used integers, but floating point numbers will work just fine...even numbers like "1.e-5" are Ok) If that's the case, you can plot it really easily:
plot 'datafile.txt' using 1
The x-values will start from 0 and go up to the number of lines in your file. See help datafile using for more information.
If you want all the points to have the same x value, you can do something like this:
plot 'datafile.txt' using (0.0):1
You'll probably get a warning about a zero range on the x axis (which isn't a problem -- gnuplot did the right thing). If you really want to get rid of the warning set the xrange before plotting (or while plotting...)
e.g.
set xrange [-1:1]
plot 'datafile.txt' using (0.0):1
or
plot [x=-1:1] 'datafile.txt' using (0.0):1
EDIT
Based on what you said in your comments below, the script you are having gnuplot run looks like:
set terminal png
set output "waveform-hy1-00000001-20120501-160221.929.raw.png"
plot 'waveform.txt' with dots # it shouldn't matter, but I always use a using statement just for clarity.
replot # <--- a replot after a plot is probably not what you want here.
set output "delta-hy1-00000001-20120501-160221.929.raw.png" #<-- Nothing will be written to this file...
A few comments -- First, are you sure that you flush/close your output file (waveform.txt) and your script file (temp) before plotting? If the output is being buffered, then there is a decent chance that one of those files is empty when gnuplot goes to read it. Next, having a plot and a replot without resetting the output file name is not (typically) what you want. What were you trying to achieve with that? You may have wanted:
set terminal png
set output "waveform-hy1-00000001-20120501-160221.929.raw.png"
plot 'waveform.txt' using 1 with dots
set output "delta-hy1-00000001-20120501-160221.929.raw.png"
replot
Although this will generate the same plot in two different files. What is the purpose of the two different files? Is there more that you're not showing? Perhaps if you paste the entire contents of the file temp along with a description of what you're trying to do, we can be of more assistance. (Also, you've mixed quotes in this script -- if you're writing the script in a c++ program, you should check to make sure that you properly escaped your quotation marks when creating temp).
Finally, what OS are you on? There's a lot about using gnuplot on windows that I have no experience with...