Histograms

In a histogram, the height of each bar (bin) represents the number of data points that fall into its interval. They are generally used to show the distribution of a variable.


In [ ]:
// Generate some random data

Random random = new Random();
data1 = [];
data2 = [];

(1..10000).each {
  data1 << random.nextGaussian();
  data2 << 2*random.nextGaussian() + 1.0;
}
print(data1[7])
OutputCell.HIDDEN

In [ ]:
new Histogram(data: data1, binCount: 25);

In [ ]:
new Histogram(initWidth:800, initHeight:200,
              title:"Wide Histogram with Manual Parameters",
              xLabel:"Size",
              yLabel:"Count",
              rangeMin: -8, 
              rangeMax: 8, 
              data: data1 + [7]*200,
              binCount: 99, 
              color: new Color(0, 154, 166));

In [ ]:
new Histogram(title:"Default is Overlap",
              data: [data1, data2],
              binCount: 99,
              names: ["old and tired", "new and improved"],
              color: [new Color(0, 154, 166),
                      new Color(230, 50, 50, 128) // transparent!
                     ]);

In [ ]:
new Histogram(title:"Stack",
              showLegend: false,
              displayMode: Histogram.DisplayMode.STACK,
              data: [data1, data2],
              binCount: 99)

In [ ]:
new Histogram(title:"Side by Side",
              displayMode: Histogram.DisplayMode.SIDE_BY_SIDE,
              data: [data1,data2], 
              binCount: 55)

In [ ]:
new Histogram(title:"Cumulative",
              cumulative: true,
              data: data1,
              binCount: 55);

In a normed histogram, the height of the bars is scaled so the area under the histogram is unity.


In [ ]:
new Histogram(title:"Normed, Area = 1.0",
              normed: true,
              data: data1,
              binCount: 55);

In [ ]:
new Histogram(log: true,  
              data: data1,
              binCount: 99);

In [ ]: