0
votes

I want to plot a simple histogram, using raw data. ie, I have a file with a single column (for testing I just put there 1000 normal random variables so that I would get a nice gaussian like histogram).

I write:

reset
set style data histogram
set style histogram cluster
plot newhistogram "A", "mydata"

But all I get is just the function itself (IE instead of the x axis being the bins, it's just a number from 0 to 1000, just like I plotted the data file itself). How can I create a proper histogram?

1

1 Answers

0
votes

Theory

To plot a histogram your data needs to be setup like this:

<cluster name 1> <data 11> <data 12> ... <data 1n>
<cluster name 2> <data 21> <data 22> ... <data 2n>
...
<cluster name m> <data m1> <data m2> ... <data mn>

Then you can set the style of your histogram with for example:

set style data histogram
set style histogram cluster
set style fill solid 1.0   #<this only makes the histogram bars filled with a color

With a data file Data.csv and n = 6 you can iterate over all values with

plot for [i = 2 : 6] "Data.csv" u i:xticlabel(1)

Example

Data.csv

col1 0.7585169 0.9014084 0.0530081 0.5387650 0.3958664 0.7884399
col2 0.5492615 0.1042125 0.4758576 0.2488184 0.0039956 0.3210850
col3 0.4668526 0.6453222 0.1703792 0.0229689 0.7916639 0.6115277

Gnuplot Script

set style data histogram
set style histogram cluster
set style fill solid 1.0

plot for [i = 2 : 6] "Data.csv" u i:xticlabel(1)

Output

Output