BREWERMAP provides all ColorBrewer colorschemes for MATLAB, with simple selection by colormap length and scheme name. Alternatively the scheme name can be preselected, after which only the colormap length is required to define an output colormap.
BREWERMAP is compatible with all MATLAB functions that require a colormap. The function consists of just one M-file that provides all of the ColorBrewer colorschemes (no mat file, no third party files, no file-clutter!). Downsampling or interpolation or repetition of the nodes occurs automatically, if required. Interpolation uses the Lab colorspace.
### Examples ###
% Plot a scheme's RGB values:
rgbplot(brewermap(9, 'Blues')) % standard
rgbplot(brewermap(9,'*Blues')) % reversed
% View information about a colorscheme:
[~,num,typ] = brewermap(NaN,'Paired')
num = 12
typ = 'Qualitative'
% Multiline plot using matrices:
N = 6;
axes('ColorOrder',brewermap(N,'Pastel2'),'NextPlot','replacechildren')
X = linspace(0,pi*3,1000);
Y = bsxfun(@(x,n)n*sin(x+2*n*pi/N), X.', 1:N);
plot(X,Y, 'linewidth',4)
% Multiline plot in a loop:
set(0,'DefaultAxesColorOrder',brewermap(NaN,'Accent'))
N = 6;
X = linspace(0,pi*3,1000);
Y = bsxfun(@(x,n)n*sin(x+2*n*pi/N), X.', 1:N);
for n = 1:N
plot(X(:),Y(:,n), 'linewidth',4);
hold all
end
% New colors for the COLORMAP example:
S = load('spine.mat');
image(S.X)
colormap(brewermap([],'YlGnBu'))
% New colors for the SURF example:
[X,Y,Z] = peaks(30);
surfc(X,Y,Z)
colormap(brewermap([],'RdYlGn'))
axis([-3,3,-3,3,-10,5])
% New colors for the CONTOURCMAP example:
brewermap('PuOr'); % preselect the colorscheme.
load topo
load coast
figure
worldmap(topo, topolegend)
contourfm(topo, topolegend);
contourcmap('brewermap', 'Colorbar','on', 'Location','horizontal',...
'TitleString','Contour Intervals in Meters');
plotm(lat, long, 'k')
### Bonus Function ###
BREWERMAP_PLOT creates a figure which shows the nodes of all ColorBrewer colorschemes.
### Bonus Function ###
BREWERMAP_VIEW creates an interactive figure that allows selection of the colorscheme, and that contains two colorbars showing colors of the colormap and the grayscale equivalent.
R2014b or later: BREWERMAP_VIEW can also update other axes' or figures' colormaps in real time, for example:
S = load('spine');
image(S.X)
brewermap_view(gca)
### Notes ###
The function BREWERMAP:
* Consists of just one convenient M-file (no .mat files or file clutter).
* Has no third-party file dependencies.
* Interpolates in the Lab colorspace.
* Requires just the standard ColorBrewer scheme name to select the colorscheme.
* Supports all ColorBrewer colorschemes.
* Outputs a MATLAB standard N-by-3 numeric RGB array.
* Uses a default length the same as MATLAB's colormaps (i.e. the length of the current colormap).
* Is compatible with all MATLAB functions that use colormaps (eg: CONTOURCMAP).
* Includes the option to reverse the colormap color sequence.
* Does not break ColorBrewer's Apache license conditions (unlike many on MATLAB File Exchange).
This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/). See the ColorBrewer website for further information about each colorscheme, colorblind suitability, licensing, and citations.
Stephen Cobeldick (2021). ColorBrewer: Attractive and Distinctive Colormaps (https://github.com/DrosteEffect/BrewerMap), GitHub. Retrieved .
Inspired by: colorGray, SC - powerful image rendering, Light Bartlein Color Maps, Vivid Colormap, Cold Colormap, Red Blue Colormap, Haxby color map, Bipolar Colormap, Color Palette Tables (.cpt) for Matlab, Perceptually improved colormaps, Generate maximally perceptually-distinct colors, Matlab colormaps as seen by color-blind users, stoplight, othercolor, colorGradient: generate custom linear colormaps, Colormaps compatible with red-green color perception deficiencies, cbrewer : colorbrewer schemes for Matlab, POLARMAP: Polarized colormap, Build custom colormaps, Custom colormap, Beautiful and distinguishable line colors + colormap, cmap2pal - Convert matlab colormap to binary .pal format, Intuitive RGB color values from XKCD, rgbmap color maps, hslcolormap, Perceptually uniform colormaps
Inspired: newcolorbar: multiple colormaps in the same axes, squink(Colors,Gamma), paruly, cbrewer2, Cyclic color map, Maximally Distinct Color Generator, Convert between RGB and Color Names, jetwhite(Colours), cmocean perceptually-uniform colormaps, How to estimate subglacial water routes, CubeHelix Colormap Generator: Beautiful and Versatile!, HCP (HeatmapCovariatePlot), MatPlotLib Perceptually Uniform Colormaps
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
Super-Duper, Stephen, Super-Duper!! You ma man, saved me an hour...
A very nice submission to upgrade your figures for good viewing by all viewers.
It helps to choose my company VI:https://www.wiscon-tech.com/
Thank you for this wonderful contribution.
@Ashutosh Goel: did something not work as documented? Please give some **written** feedback so that I can fix any errors or bugs that you might have found.
My legend colours and lines do not match in the figure. I used brewermap(9, 'BuPu').
Thanks for your help!
¡Hermoso! , muchas gracias. Excellent feature that makes every plot attractive!, Thank you again.
Wow this tool is fantastic, thanks so much!
Great job! Thanks a lot!
Super great!!!
Incredibly nice bit of code, does exactly what I was looking for and very easily. The GUI to pick a colormap is also great!
fantastic! that is what I am look for! RdYlBu is prefect! It is friendly to colorblind(red/green) people and also show things very clear
Awesome! Having used the colorbrewer in R for a while, this really improves the graphics quality a lot, many thanks!
Excellent! I've been looking for nice colormaps for so long! Many many thanks!
PERFECT!!!!! Thank you very much~
Thank you!
I thought I had a good color selection method. Nah. This blows it away!
Thank you! Great work!
F**cing beautiful. Great job!!!
Very intuitive, great preset color schemes, and easy to scale to any size data set.
This function is excellent, easy to use, and works perfectly, right out of the box. Thanks for sharing, Stephen.
M S : Thank you for your feedback. I am glad that you found my submission easy to use, as the convoluted usage of other ColorBrewer submissions on MATLAB File Exchange was one of the main motivators to write this. I intended that usage of this function should be as much like the standard colormap functions as was reasonable and feasible.
Your suggestions and observations about the unsuitability of the ColorBrewer schemes for colorblind users are very true. As you point out, the white middle color is unclear in many situations, and not just for readers with vision deficiencies.
However I did not create the ColorBrewer schemes (credit goes to Cynthia Brewer for this), nor do I make any claims about their suitability for a particular purpose, other than to say that they are "attractive, distinguishable colors". Any claims about the suitability for any particular purpose are solely those of Cynthia Brewer, for whom I am not responsible. The sole purpose of this submission is to provide the best access to the ColorBrewer colorschemes for MATLAB File Exchange users.
You might like to consider using the colormapeditor:
http://www.mathworks.com/help/matlab/ref/colormapeditor.html
Writing a colorblind-friendly maximally distant colormap generator would be quite interesting, but this is a clearly a very different task to this simple porting of Cynthia Brewer's existing colorscheme data. For a start, each of protanopia, deuteranopia, tritanopia, protanomaly, deuteranomaly, and tritanomaly would require a completely different set of permitted colors. If you are interested, contact me and we could develop this together.
Pros: supports colorblind palette, which is desperately needed for matlab visualization. Easy to use.
Cons: poor for any plotting purpose; it is not designed for any visualization where there's a background color. For example, for a 'divergent', 'colorblind friendly' scheme, the middle color is always white or off white, which is obviously terrible for plots with a white background.
I wish there were a way to combine another FEX submission, distinguishable_colors--which not only arranges maximally distant colors, but takes into account background color--with colorblind friendly implementation.
You are completely correct that it is possible to redistribute the ColorBrewer colorschemes: in fact this is explicitly permitted by the Apache license that they are released under.
Note though the very first license condition for redistributing ColorBrewer says that "Redistributions as source code must retain the above copyright notice, this list of conditions and the following disclaimer". So when someone redistributes it, it must be accompanied by the same Apache license*. However MATLAB File Exchange does not permit any license to be used other than the BSD license:
http://www.mathworks.com/matlabcentral/FX_transition_faq.html
"For consistency, the BSD license will be the standard for the File Exchange".
So we reach a minor impasse: to redistribute ColorBrewer requires an Apache license, to submit to MATLAB FEX requires a BSD license. Snap. I could distribute a complete version of this function under an Apache license, but not on MATLAB FEX.
Several other submissions have simply ignored ColorBrewer's Apache license, but hopefully FEX does not turn into an exchange of any licensed code that happens to take peoples fancy.
* For an example of this, scroll down to the bottom of the excel spreadsheets that are available from http://colorbrewer.org/
Nice job, but not sure why you state you cannot redistribute the colormaps since the website suggests that you can, assuming you meet the requirements. It does, however, specifically state you cannot call the software "ColorBrewer"...
see http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html
Beautiful work, Stephen.
A very nice submission to upgrade your figures for good viewing by all viewers.
Excellent help and examples for use. I found the colorbrewer.org web site interesting too.