Functions > Statistics > Graphical Statistics > Example: Histograms
  
Example: Histograms
Create histograms to present data coming from an experiment designed to measure the speed of light.
Histograms are created by specifying an intervals vector or an integer as the first argument to the hist and histogram functions.
The following two vectors contain the data recorded in m/s or km/hr.
Click to copy this expression
Click to copy this expression
Specifying an Intervals Vector
1. Use the min function to create a set of bins for V1 so that the V1 and V2 histograms can be compared over the same intervals.
Click to copy this expression
Click to copy this expression
2. Use the histogram function to create the two histograms.
Click to copy this expression
Click to copy this expression
The histogram function accepts a vector containing units.
3. Use the hist function to count the number of elements of V1 and V2 contained in each bin.
Click to copy this expression
Click to copy this expression
4. Define the x-axis as column 0 of H11, normalized by 108 to make it easier to read.
Click to copy this expression
5. Define a function that removes the units from a united variable or scalar and use it to define the vertical markers as the unitless elements of bins1.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
6. Plot a bi-histogram of the data sets, and then add vertical markers to show the mid point of each bin.
Click to copy this expression
As can be seen in the plot:
The number of bins equals one less than the length of the intervals vector.
The V1 and V2hist output vectors are represented by the bars above and below the horizontal axis, respectively.
As the vertical markers show, each bar is centered around its corresponding bin value.
Specifying an Integer to Indicate Number of Intervals
1. Define the interval parameter that represents the number of subintervals of equal lengths.
Click to copy this expression
2. Use the histogram function to create the two new histograms.
Click to copy this expression
Click to copy this expression
3. Use the hist function to count the number of elements of V1 and V2 contained in each bin.
Click to copy this expression
Click to copy this expression
The hist function now returns result vectors of length P for V1 and V2.
The sum of elements in each vector adds up to the number of elements in V1 and V2.
4. Define the x-axis as column 0 of H21, normalized by 108 to make it easier to read.
Click to copy this expression
5. Extract the unitless values from bins2 and use them to plot the vertical markers that mark the mid point of each bin.
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
Click to copy this expression
6. Plot the new bi-histogram of the data sets.
Click to copy this expression
As can be seen in the plot:
The number of bins equals the interval parameter P.
The V1 and V2hist output vector is represented by the bars above and below the horizontal axis, respectively.
As the vertical markers show, each bar is centered around its corresponding bin value.