Martin Vegter
Martin Vegter

Reputation: 527

gnuplot: misinterpreting data (histogram)

I have following sample data file, which I want to plot in gnuplot as a histogram

1   1
2   2
4   3

I am using following command to plot the data: plot "sample.data" with boxes, which produces following chart:

      ##
      ##
  ######
  ######
########
########

whereas, the chart should look like this (there should be no value for 3):

      ##
      ##
  ##  ##
  ##  ##
####  ##
####  ##

From help boxwidth I understand that: "By default, adjacent boxes are extended in width until they touch each other". This seems like a serious bug/misfeature to me. I want my data to be represented correctly, and not to plot nonexistent data. How can I trust gnuplot to represent my data correctly, when this simple example fails?

Upvotes: 3

Views: 645

Answers (1)

Christoph
Christoph

Reputation: 48430

If you had read also the other sentences around it, you would have seen, that the boxes are calculated automatically only if no exlicit boxwidth was specified. This can be done either by using a third column, or by setting one width with set boxwidth:

set boxwidth 1
plot "sample.data" with boxes

or

plot "sample.data" using 1:2:(1) with boxes

Note, that the boxwidth is given in units of the x-axis.

Upvotes: 3

Related Questions