0

Following the answers to this question: Histogram using gnuplot? and some other sources I created this script:

set terminal postscript eps enhanced color
set title "Histogram\_CreatesFile"

colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'Histogram_CreatesFile.eps'
set yrange [0:]
set style fill solid 0.8 border -1
bin_width = 0.2
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
plot 'Histogram_CreatesFile.txt' using (rounded($1)):(1) smooth frequency with boxes lc rgb colour1 notitle

and I have a test data file:

0
0.2
0.4
0.41

and everything is beautiful, but I get a weird empty space on the left of the first bar: enter image description here

how can I make the graph start from the first bar, when I don't know apriori what are the values in the data file (i.e. it might start from other value than 0)?

Community
  • 1
  • 1
Grzenio
  • 35,875
  • 47
  • 158
  • 240
  • 1
    Also note that since you're using a double quoted string for `set title`, you might need two backslashes to prevent the enhanced text making the `C` a subscript. Alternatively, you can use the `noenhanced` option I would think. – mgilson May 17 '13 at 13:44

1 Answers1

2

It seems to me that the stats command could probably help you out here.

set terminal postscript eps enhanced color
set title "Histogram\_CreatesFile"

colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'Histogram_CreatesFile.eps'
set yrange [0:]
set style fill solid 0.8 border -1
bin_width = 0.2
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )

stats 'Histogram_CreatesFile.txt' using (rounded($1)) nooutput
set xrange [STATS_min-bin_width/2.:]

plot 'Histogram_CreatesFile.txt' using (rounded($1)):(1) smooth frequency with boxes lc rgb colour1 notitle

stats was added in gnuplot4.6(?). Prior to that, the trick that I always used for these things was to plot to the dummy terminal and pick up the minimum from the special read-only variable GPVAL_X_MIN. stats is much cleaner and more powerful though and should be used now that the current stable version is 4.6.

mgilson
  • 300,191
  • 65
  • 633
  • 696