gnuplot - plot difference between two columns with pseudocolumn 0 - windows

I have a .csv file organized as follows:
425;490
160;343
390;487
35;231
...
I want to plot the difference of (row1-row2) on the y-axis, and the pseudocolum 0 as the x-axis.
So far, i've tried
plot "test.txt" using $0:($1-$2)
which throws
column() called from invalid context
On the other hand
plot "test.txt" (using $0:($1-$2))
seems to work but throws
'plot "test.txt" (using $0:($1-$2))'
in the console.
So my question:
What would be the correct syntax?

plot 'text.txt' using 0:($1-$2)
or
plot 'text.txt' using ($1-$2)

Related

Adjust time values in the using statement

I try to compare two data files that show the raise in memory consumption vs. time. The data stems from two tests that I executed on different times, I'm trying to make the difference (or equivalence) obvious by shifting the second plot in the x and y axes.
Here is my test.plt script (the plot line is wrapped for this question):
reset
set title "Memory consumtion of process"
set style data fsteps
set xlabel 'Zeit (HH:MM:\nSS.ddd)'
set timefmt '"%H:%M:%S"'
set xdata time
set xrange ['"10:00:00"' : '"13:00:00"']
set yrange [12000 : 20000]
set ylabel "Memory\nin KBytes"
set format x "%H:%M:\n%.3S"
set grid
set key left
plot 'mem-2015-11-26-1229.dat' using 1:2 with lines,
'mem-2015-11-26.dat' using 1:($2-1500) with lines
There is no problem with y since this is a normal scalar value. But I'm having difficulties to do the same with the x axis, this is how I tried to shift x (all with no success):
plot 'mem-2015-11-26-1229.dat' using 1:2 with lines,
'mem-2015-11-26.dat' using ($1-3600.0):($2-1500) with lines
Not even using the alias ($1) seems to work on time axis:
plot 'mem-2015-11-26-1229.dat' using 1:2 with lines,
'mem-2015-11-26.dat' using ($1):($2-1500) with lines
Both give the following warning (and no output for the second file):
"test.plt", line 15: warning: Skipping data file with no valid points
What am I doing wrong? Is it even possible to calculate time values at all? If yes, how?

Plotting multiple columns with a for loop in gnuplot, key doesn't work

I have file with many columns that I'd like to plot as follows:
plot for [i=1:30] 'test' using 1:i w lp
This gives the plot I want, but when I do set key, then the key I see has all lines labeled as 1:i:
How can I make this output more meaningful, by actually displayin the value of i?
If you don't set an explicit title, gnuplot selects an automatic title based on the plain plot command call. If you want a meaningful title, you must give it explicitly, like
plot for [i=1:30] 'test' using 1:i w lp title sprintf("column %d", i)

For-loops in gnuplot

I'm getting confused with how to use for-loops in gnuplot.
The following code works fine:
plot for [quadIter=0:270:90] \
path using 1:(column(1 + quadIter))
It plots 4 curves on one graph.
I also want to plot 4 horizontal lines on the same graph. I have written the following script to do this:
plot for [quadIter=0:270:90] \
path using 1:(column(1 + quadIter)) , \
path_to_expt[1 + quadIter/3: 19] \
But it only plots one additional line on the graph, so it is not being included in the for-loop. Please can you tell me how to get the additional line included in the loop?
Also, the constant value that is plotted is not the value I was expecting it would plot. Please can you tell me how to print the value of quadIter to the screen, so that I can check it against the value in the file?
Finally, I tried just to plot the 4 horizontal lines with this script:
plot for [quadIter=0:270:90] \
path_to_expt[1 + quadIter/3: 19] \
But I got an error message, "Non-numeric string found where a numeric expression was expected". I find this strange, as I didn't get this error message when I ran the second script but, as the second script isn't working how I would like, hopefully by getting the second and third scripts to work, I will have a better understanding of how for-loops work in gnuplot.
Thank you for your help!
The for iteration applies only the the current plot expression. The line
plot for [i=1:4] i*x, i*x**2
creates five plots, whereas in order to get eight plots you must do
plot for [i=1:4] i*x, for [i=1:4] i*x**2
Concerning your last expression path_to_expt[1 + quadIter/3: 19]: array expressions aren't supported by gnuplot (however path_to_expt looks like one).

Matlab - Symmetric PSD of an Image using fft

I wanted to have one dimensional PSD for an Image calculated (along rows and columns separately) using matlab.
I use the following snippet for the same.
F=fft(img,[],2);%FFT along dim2
F=fftshift(F,2);
mtf=(abs(F)).^2;
mtf_mean = mean(mtf,2);% Mean of all contents of a row
mtf_mean_norm = mtf_mean/max(max(mtf_mean)); %Normalization to 1
plot(mtf_mean_norm);
When I plot it, I expected a symmetrical plot with respect to a center (and that's what I want). But, I happen to see that two parts look asymmerical like in the attached figure.
Looks like I have a code bug, Any clues what am I missing ?
Image url: http://i.stack.imgur.com/RrLIt.jpg
I am not an image processing person, but just from my own stats knowledge I would say.
you should use mtf=abs(F)'*abs(F) instead of mtf=(abs(F)).^2. I got the following figure
here is the code that generates the figure.
> img=randn(50,50);
> F=fft(img,[],2);%FFT along dim2
> F=fftshift(F,2);
> mtf=abs(F)'*abs(F);
> mtf_mean = mean(mtf,2);% Mean of all contents of a row
> mtf_mean_norm = mtf_mean/max(max(mtf_mean)); %Normalization to 1
> plot(mtf_mean_norm);
> plot(mtf_mean_norm);

How do I make a plot in gnuplot with the lowest value automatically subtracted from the y data?

I am plotting the creation times of a large batch of files in gnuplot to see if they are created linearly in time (they are not).
Here is my code:
#!/bin/bash
stat -c %Y img2/*png > timedata
echo "set terminal postscript enhanced colour
set output 'file_creation_time.eps'
plot 'timedata'" | gnuplot
The problem I have is that the y data are the creation time in seconds since unix start time, so the plot just has 1.333...e+09 on the y-axis. I would like to have the creation time of the first file scaled to zero so that the relative creation times are readable.
I encounter this problem in a number of data-plotting contexts, so I would like to be able to do this within gnuplot rather than resorting to awk or some utility to preprocess the data.
I know the first time will be the smallest since the files are named serially, so is there a way to access the first element in a file, something like
`plot 'data' using ($1-$1[firstelement])`
?
I think you can do something like that...(the following is untested, but I think it should work...). Basically, you have to plot the file twice -- the first time through gnuplot picks up statistics about the dataset. The second time through, you use what you found on the first run-through to plot what you actually want.
set terminal unknown
plot 'datafile' using 1:2
set terminal post enh eps color
set output 'myfile.eps'
YMIN=GPVAL_Y_MIN
plot '' u 1:($2-YMIN)
If you have gnuplot 4.6, you can do the same thing with the stats command.
http://www.gnuplot.info/demo/stats.html
EDIT It appears you want the first point to provide the offset (sorry, misread the question)...
If you want the first point to provide the offset, you may be able to do something like (again, untested -- requires gnuplot >= 4.3):
first=0;
offset=0;
func(x)=(offset=(first==0)?x:offset,first=1,x-offset)
plot 'datafile' using (func($1))
Gnuplot accepts unix commands, so you can say something like
gnuplot> plot "< tail -3 test.dat" using 1:2 with lines
in order to plot just the last three lines. You can use something like this for your purpose. Moreover, if you want to plot let's say from line 1000 to 2000
plot "<(sed -n '1000,2000p' filename.txt)" using 1:2 with lines
You can check this website, for more examples.
I found a related stackoverflow question here and exploited the awk script from one of the answers:
#!/bin/bash
stat -c %Y img2/*png > timedata
echo "set terminal postscript enhanced colour
set output 'file_creation_time.eps'
unset key
set xlabel 'file number'
set ylabel 'file creation time (after first)'
plot \"<awk '{if(NR==1) {shift = \$1} print (\$1 - shift)}' timedata\"" | gnuplot
The output looks like this (these are not the data I was talking about in my question, but similar):
So, gnuplot can do what I want but it does depend on the UNIX environment...
I also tried mgilson's method:
plot 'timedata'
YMIN=GPVAL_Y_MIN
plot '' u ($1-YMIN)
but gnuplot (my version is 4.4.2) did not find the minimum correctly. It came close; it looks like it plotted such that the minimum of the y range is 0:

Resources