File Exchange

image thumbnail

Coloured bar chart

version 1.2 (1.3 KB) by Malcolm McLean
Simple wrapper to bar allowing you to specify bar colors and labels.

1 Download

Updated 29 Nov 2014

View License

Quite frequently you want to color the bars in a bar chart according to your own scheme - e.g. to highlight an anomalous measurement in red. The bar function doesn't make it easy to do this, but there is a way.
Also, only occasionally do you want the x-axis labels to be the default 1 2 3 ... So for convenience this function takes a series, a colour vector, and a list of labels.

Cite As

Malcolm McLean (2019). Coloured bar chart (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (2)

A simple modification to use RGB color vectors:

for ii = length(x):-1:1
h = bar(x(1:ii), 'FaceColor', colors(ii,:));
hold on;

set(gca, 'xticklabel', labels);

for ii = 1:2:size(varargin, 2)
set(h, varargin{ii}, varargin{ii+1});


Thanks, this is useful. There is a typo on line 20 though, 'varagin' should be 'varargin'




MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Inspired: superbar