MATLAB Examples

This is an example of how to create a bivariate histogram in MATLAB®.

Read about the histogram2 function in the MATLAB documentation. This function is available in R2015b or newer.

For more examples, go to MATLAB Plot Gallery

% Check version
if verLessThan('matlab','8.6')
    error('histogram2 is available in R2015b or newer.')

% Load ride data from Boston's bike sharing program
load rideData rideData

% Create bivariate histogram plot using the histogram2 function
histogram2(rideData.Duration, rideData.birth_date, 'BinWidth', [2 2])
xlabel('Length of Ride')
ylabel('Birth Year')
zlabel('Number of Rides')
title('Ride counts based on ride length and the age of the rider')

% Adjust view