1

I'm having trouble with the boxwidth option in gnuplot when trying to plot a histogramm. Here is the gnuplot script I use to plot the histogram of random numbers normally distributed:

# Parameters
n=50 # number of intervals
min=-5. # min value
max=5. # max value
width = (max-min)/n # interval width

# Function used to map a value to the intervals
hist(x,width)=width*floor(x/width)+width/2.

# Output
set term png
set output "histogram.png"

# Graph
set xrange [min:max]
set yrange [0:]
set xtics min,(max-min)/5,max
set boxwidth width*0.9
set style fill solid 0.5
set tics out
set yzeroaxis # Add a vertical dotted line at x=0 to show centre (mean) of distribution
set xlabel "Random number"
set ylabel "Frenquency (%)"

# Count and Plot
plot "Random_numbers.txt" u (hist($1,width)):(100.0/ 10000 ) smooth freq w boxes notitle

With this script, the "boxes" are just "lines" (boxes with no width). Do you know why ?

When I remove the line "set boxwidth width*0.9", it works except that the boxes width is "width" (the boxes are touching the adjacent boxes).

Many thanks in advance !

NB : Sorry the image uploading is not working, I hope you can imagine my problem (I want to get a plot like this:

enter image description here

but in my case the boxes have no width, they are just vertical lines) ...

1

I would try a couple of things:

set boxwidth 0.2

And if that works, which it should, then:

n=50.0

Your min and max variables are floats, so you should get a floating point division when you compute width, even with an integer n, but I've noticed some unexpected behaviour from gnuplot in this regard, so it's worth a try.

0

Seems to work for me (gnuplot Version 4.6 patchlevel 3). You could try

set boxwidth width*0.9 absolute

which appears the same for me. There's an online gnuplot tool but I dont know how to use it.

These online demos which claim to be version 4.0 use a constant value with seemingly ok results:

set boxwidth 0.2 absolute
  • I tried to use this but it doesnt change anything unfortunetely... I have Gnuplot Version 4.0 patchlevel 0 – JoVe Jul 7 '15 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.