image thumbnail

MATLAB Plot Gallery - Horizontal Bar Plot

by

 

24 Feb 2012 (Updated )

Create a horizontal bar chart

Horizontal_Bar_Plot

This is an example of how to create a horizontal bar chart in MATLAB®.

Read about the barh function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Create the data for the temperatures and months
temperatures = [40.5 48.3 56.2 65.3 73.9 69.9 71.1 59.5 48.7 35.3 31.7 30.0];
months = {'Dec', 'Nov', 'Oct', 'Sep', 'Aug', 'Jul', 'Jun', 'May', 'Apr', 'Mar', 'Feb', 'Jan'};

% Plot the temperatures on a horizontal bar chart
figure
barh(temperatures)

% Set the axis limits
axis([0 80 0 13])

% Add a title
title('Boston Monthly Average Temperature - 2001')

% Change the Y axis tick labels to use the months
set(gca, 'YTick', 1:12)
set(gca, 'YTickLabel', months)

Contact us