whoever
whoever

Reputation: 585

Using gnuplot for discrete distribution

Is there a relatively simple way to plot a graph of distribution of discrete data?

E.g. we have some set of float values over a range from 0 to 1 and what we need is a chart diagram over 10 ranges ([0.0, 0.1], [0.1, 0.2], ..., [0.9, 1.0]) of how many of given floats hit the respective range.

Thanks.

Upvotes: 2

Views: 4107

Answers (1)

psibar
psibar

Reputation: 2000

This can easily be done with a "frequency plot". If the frequency option is set "all points with the same x-value are replaced by a single point having the summed y-values" (help smooth frequency). This means if you assign to every point the y-value 1 the result will be the number of all points having a particular x-value.

Now, in order to be able to sum up all points within a certain range you can use a function which rounds off the values of the data as suggested here

bin(x)=0.1*floor(x/0.1)
plot "datafile.txt" using (bin($1)):(1.0) smooth frequency with boxes

You might also want to tweak the appearance of the boxes with set boxwidth and set style fill.

Upvotes: 1

Related Questions