File Exchange

image thumbnail

cbrewer : colorbrewer schemes for Matlab

version (85.6 KB) by Charles
This function loads colormaps based on the color brewer schemes (


Updated 18 Sep 2015

View Version History

View License

This function produces a colorbrewer table (rgb data) for a given type, name and number of colors of the colorbrewer tables. For more information on 'colorbrewer', please visit:

The tables were generated from an MS-Excel file provided on the website
This function also allows to use a variable number of colors for each colortable by interpolating the RGB indices
Based on the original data, there is only a certain number of colors available for each color scheme. When 'ncol' is larger then the maximum number of colors originally given, an interpolation routine is called (interp1) to produce an "extended" colormap.

To see the various colormaps available according to their types and names, simply call: cbrewer()
This product includes color specifications and designs developed by Cynthia Brewer (

Cite As

Charles (2021). cbrewer : colorbrewer schemes for Matlab (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (54)

mariano real

This is a great tool, thanks a lot!

I'm getting this error in the MATLAB R2020b version, which did not get in previous versions.

I does not allow me to plot. I think it is related to Serena's one.

Could anybody help me?

Error using colormap (line 105)
Colormap must be an Mx3 array of type single or double with values in the range [0,1] or an Mx3 array of type uint8.

Howard Labido

Just wondering, can I use it on common objects like used plastic bottles?
I have a waste treatment project where early detection and removal of certain waste is needed.

Serena Lee

I found my error. Works perfectly. Thanks

Serena Lee

I am having trouble using this toolbox.
I tried using a few different commands to generate a colormap but when I try to call the colormap I get the error command:

Error using matlab.ui.Figure/set
There is no colour property on the Figure class.

These are the different commands I have tried:




I also tried extracting the colormap directly from the colorbrewer.mat file, but this generated data that was not in the 0-1 range required by colormaps.
Can anyone clear up how to call the colormaps when plotting a figure.
Thanks very much.


Bryce Grier

Mohd Lotfi

Szu-Yu Lee

Yunhan Gui

Vladimir Calderón


very useful. Thanks!

Megan Morrison

Hi Charles, this toolbox is great! I have found one bug in the interpolate_cbrewer.m function though. The "round" function at the very end of the script turns all values to 0,1, ruining the interpolation, at least in my version of Matlab.

Ivo A.


Xizi Li

wakhidatik nurfaida


This is really helpful! Thanks!

Christina Tsalicoglou

Marios Matthaiakis

Very useful! Thank you!

Niall O'Keeffe


thanks. this is great - super useful


William Frost


Mx Shen

Very useful!


Great! very useful!

Giacomo Rossitto

Hi, excellent colormaps.
I'm wondering if it is possible to shift the with color (normally at the center of the diverging colormap) in a custom position?

Xinyu Wu

Simple and Great! Many thanks.


Great function. easy to use. keep up the great work. Many thanks.


Stephen Cobeldick

I have no problem if you received Ms Brewer's permission to distribute her data. This is great news!

It is usual with copyrighted information to either include the appropriate license, or if permission was granted by the copyright holder to clearly state that permission was granted for that use.

But this permission is not stated anywhere in your comments, in your code, in your license, or in your description. This is the very first time that you have mentioned it.

Unless you state that you have this permission (and this is the first time), then how am I (or anyone else) supposed to know that this is the case? My mind-reading ability is a bit rusty, so I apologize if I was not able to read your private emails and know that your have this permission.


I got Mrs Brewer's permission in writing when I wrote the code. She didn't have any problem with it so I don't why you do.

Stephen Cobeldick

Note that this submission still breaks the license conditions of Cynthia Brewer's ColorBrewer colorschemes, which require her APACHE license to be included:


I updated the function to correct the problem pointed out by Katak. I also added a new script that should help create a jet-like color table based on different RGB "references" (see change_jet.m), as a reply to Chavdar.

Katak Goreng

Hi Charles,
Many thanks for you contribution. Excellent toolbox.
I just would like to point out 1 thing. Loading the colorbrewer.mat, there is 9 color maps. However, when you type brewer in command line, only 8 are displayed. "spectral" map was not shown. Typing "spectral" would load the colormap just fine though.

cheng joylin


Great tool! Great colors!

is there a chance that you could add a diverging map going from blue to green to red as in jet, but using the red and blue from your RdBu map and the third darkest green from your RdYlGn map?




Stephen Cobeldick

Users wanting a more user-friendly version of the ColorBrewer colorschemes can try my submission, which is available here:

Rather than simply providing the data, it actually provides a function that can be used like any other standard colormap function in MATLAB ("hsv","jet","cool","hot","gray","bone",...).

For simple usage it requires only the map length and scheme name to define a colormap. The user can also set a default colorscheme and it can then be called exactly like any other MATLAB colormap function (i.e. a drop-in replacement). For colormaps larger than those defined by the original ColorBrewer data, it interpolates -all- of the ColorBrewer defined nodes for that colorscheme (not just the ones from the largest pre-defined colormap) to closer match the original ColorBrewer colormaps. Keeping all of the data in just one M-file means no file-clutter either!

Importantly my submission does NOT include any of the ColorBrewer data: these must be downloaded separately as an excel spreadsheet and are merged into the main M-file using a helper function (it is easy, and instructions are included!). The Color Brewer data are copyright under an Apache license:


Lieven Verbeke

Excellent! Easy to use as well.

John D'Errico

As much as I like the idea, the implementation and the help could use some repair. It is not terribly friendly. It took me some time to figure out how to call it. I had to edit the code just to figure out the options, and to see that it is case sensitive, etc.

But once you figure out how to run the code, it should be useful. If you don't use it terribly often though, you may find yourself going through those explorations every time you need it.

G Yee

Wonderful colormaps! I've been looking for a 'qualitative' dark colormap to use for my colorblind boss.

Since I'm a newbie, it took me a while to figure out how to do 2-D plots with this. Here's my code:

% Generate color-blind friendly colormap
colors = colormap(cbrewer('qual', 'Dark2', N));

% Example plot
x = 1:5;
N = 12;

for i = 1:N
y = x*i; % some big calculation
figure(1); hold on;
p = plot(x,y, 'Color' ,colors(i,:), 'LineWidth', 2);



Johannes Keyser

Beautiful maps, highly useful, Thanks a lot!

Just the zip archive could use a little cleaning (it contains unnecessary hidden files: ._cbrewer.m ._interpolate_cbrewer.m ._plot_brewer_cmap.m).


works perfectly. very easy to use and a great improvement over the Matlab defaults. Thank you!



Since a colleague introduced me to Brewer colour schemes I've been looking for a way to use them in matlab without manually entering all the RGBs. Very useful.

Jan Neggers

Andrew Bliss

Nice to see someone port these color scales to Matlab. Thanks!

[You don't need to include the hidden files or the preview jpg in the download].

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!