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 [1]:
// Generate some random data

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

(1..10000).each {
  data1 << random.nextGaussian();
  data2 << 2*random.nextGaussian() + 1.0;
}
OutputCell.HIDDEN
In [2]:
new Histogram(data: data1, binCount: 25);
In [3]:
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 [4]:
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 [5]:
new Histogram(title:"Stack",
              showLegend: false,
              displayMode: Histogram.DisplayMode.STACK,
              data: [data1, data2],
              binCount: 99)
In [6]:
new Histogram(title:"Side by Side",
              displayMode: Histogram.DisplayMode.SIDE_BY_SIDE,
              data: [data1,data2], 
              binCount: 55)
In [7]:
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 [8]:
new Histogram(title:"Normed, Area = 1.0",
              normed: true,
              data: data1,
              binCount: 55);
In [9]:
new Histogram(log: true,  
              data: data1,
              binCount: 99);
In [ ]: