1

I try to reproduce a simple histogram with Gnuplot with the simple macro:

reset
n=9 #number of intervals
width=1 #interval width
hist(x,width)=width*floor(x/width)
set terminal pngcairo size 800,500 enhanced font 'Verdana,14'
set output "test.png"
set boxwidth width
set style fill transparent solid 0.5 border #fillstyle

set xrange [*:*]
set yrange [0:2.]

set xlabel "x"
set ylabel "Freq."

plot "const.dat" u (hist($1,width)) smooth freq w boxes lc rgb "orange" notitle

whit the follow data:

 1.1
 1.1
 1.1
 1.1
 1.1
 1.1
 1.1
 1.1

Now I like to understand how the hist(x,width) works in the sense:

hist(x,width)=width*floor(x/width)

works with every numbers taking the width=1 and then:

hist(1.1,1)=1*floor(1.1/1)=1

and so on, right?

Now (hist($1,width)) take all the elements in the columns and applay the hist function to everyone.

And I can be able to make the follow plot with the macro above:!enter image description here

Question: If I use (hist($1,width)):(1.0) I Don't understand whit the plots change as all the elements stay in one single boxes (from 0.5 to 1.5) ? enter image description here

1 Answer 1

1

In the first case you specify only a single column in the using statement. Since you need at least two (x and y-value), the specified value (your hist(...)) is used as y-value and the row number as x-value. The statement smooth frequency works such, that it takes all points with the same x-value and sums up the corresponding y-values. In your first example you have no equal x-values since the row number is used.

In the second example, you use the hist(...) value as x-value, which is 1 for all rows. The y-value is 1.0. So you get a single box at x=1 and y=8 (the number of rows).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.