2
votes

I have crawled many similar questions without finding the proper problem/question/answer...

I want to use gnuplot to make a histogram plot out of a distributed data file with bars/boxes of equal width and intervals. So I need to count/integrate over the width(=1) of my bars. That's why I wanted to use the 'smooth frequency' command:

#gnuplot
bin(x)=floor(x+0.5)
set boxwidth 0.8 relative
set style fill pattern

set grid
set xrange [0:11]
set yrange [0:3]
set xtics in 0,2,10
set mxtics 2
set ytics 0,1,3
set mytics 1

p 'data.dat' u (bin($1)):(1) smooth freq w boxes

#data.dat
2.489
7.5
9.128
9.567

I tried it and the result was the same, as with my handmade file plotted with boxes:

#gnuplot2
[...]
p 'data2.dat' w boxes

#data2.dat
2 1
8 1
9 1
10 1

Smooth frequency seems to do its job properly, but the result is not what I intended to do...: Image

Then I figured out, what the problem is. It is solved using my handmade data3.dat:

#gnuplot
p 'data3.dat' w boxes

#data3.dat
1 0
2 1
3 0
4 0
5 0
6 0
7 0
8 1
9 1
10 1

Image

So the problems are the holes in my data range, that aren't counted as '0'. With these holes, gnuplot seems to adjust the box width by itself to fit in the whole space left. How can I prevent this to get my desired result?

1

1 Answers

3
votes

I think the problem is the relative key. Try:

set boxwidth 0.8 absolute