## Wednesday, September 14, 2011

### Statistic analysis using gnuplot (0)

I will talk about statistic analysis using gnuplot in this article. The following contents are covered---maximum, minimum, mean value, standard deviation.

We begin with the maximum and minimum as they are the simplest. There are two gnuplot defined variables (to see all the gnuplot variables use command "show variable all"), GPVAL_DATA_Y_MAX and GPVAL_DATA_Y_MIN. They are the maximum and minmum y value in the data file which you just used to plot. So after plotting you look over the gnuplot defined variables and you find the maximum and minimum values.

The mean value is a bit difficult. There is no such a gnuplot defined value. To find it out we will play a trick. There is smooth option called "unique" which makes the data monotonic in x and points with the same x-value are replaced by a single point having the average y-value. So it is appropriate for finding the mean value. We use command
```plot "data_t.dat" u (constant-value):(\$n) smooth unique w point
```
to plot the mean value. Here constant-value is an arbitrary constant and \$n is the column which contains the random data. Note that there is only one point plotted using the above command, so plot style line can not be used. To plot the the mean value using a line we may need to use xerrobars plot style. (Next time I will give a method to plot it using plot style line.)
```plot "data_t.dat" u (constant-value):(\$n):(xerrobar-length) smooth unique w xerrorbars
```

Now we come to plot the data points, maximum, minimum and mean value to a picture. And standard deviation is left next time.
```reset
plot "rand_t.dat" u 1:2	#To get the max and min value
ymax=GPVAL_DATA_Y_MAX
ymin=GPVAL_DATA_Y_MIN
ylen=ymax-ymin
xmax=GPVAL_DATA_X_MAX
xmin=GPVAL_DATA_X_MIN
xlen=xmax-xmin
#plot
set term png
set output "statistic.png"
set xrange [xmin:xmax]
set yrange [ymin-0.5*ylen:ymax+0.5*ylen]
set xlabel "time(ms)"
set ylabel "Random Signal(Arbitary Unit)"
plot "rand_t.dat" u 1:2 w p pt 7 ps 0.5 notitle,\
"rand_t.dat" u (xmax+0.1*xlen):(\$2):(1.1*xlen)\
smooth unique w xerrorbars notitle,\
ymax w l lt 3 notitle,\
ymin w l lt 3 notitle
#plot raw data, mean value, maximun and minimun respectively
#There is only one data point for the mean value. To make it
#looks like a line, we plot it using a xerrorbars plot style.
```
rand_t.dat can be downloaded here. Picture statistic.png is shown below. Statistic analysis using gnuplot--maximum,minimum and mean value

#### 1 comment:

1. Every person has the passion in any aspects or things.
If you love something and it came in front of you it completes your day and your mood turns into something you won't expected.
I love your work and I want to read more about it. Visit my site if you have time . Thank you.

triciajoy.com

www.triciajoy.com 