Code covered by the BSD License  

Highlights from
ColorBrewer: Attractive and Distinctive ColorMaps

Be the first to rate this file! 32 Downloads (last 30 days) File Size: 6.44 KB File ID: #45208
image thumbnail

ColorBrewer: Attractive and Distinctive ColorMaps

by

 

22 Jan 2014 (Updated )

The complete palette of ColorBrewer colormaps. Simple selection by scheme name and map length.

| Watch this File

File Information
Description

### Why This Function? ###

Provides RGB colormaps of the ColorBrewer color schemes, especially intended for mapping and plots with attractive, distinguishable colors. The function is compatible with all MATLAB functions that require a colormap, and consists of just one Mfile that provides all ColorBrewer colorschemes. Downsampling or interpolation of the nodes occurs automatically, if required, using the scheme's complete palette. As an option, the colormap color sequence can be returned reversed. Just two inputs select and define each output colormap: the colormap length and the colorscheme name.

Calling brewermap('demo') creates a figure showing all of the available colorschemes.

See the ColorBrewer website for further information about each colorscheme, colorblind suitability, licensing, and citations: http://colorbrewer.org/

### Download Required ###

It is not possible to offer the ColorBrewer colorschemes on MATLAB Exchange as they use an Apache license. Before using this function a spreadsheet containing the RGB values needs to be downloaded directly from http://colorbrewer.org/. These are then inserted into the Mfile <brewermap.m> using the helper function <colorbrewer_read.m>... step-by-step instructions are included!

### Examples ###

% Plot a scheme's RGB values:
rgbplot(brewermap(13,'Blues')) % normal
rgbplot(brewermap(13,'*Blues')) % reversed

% View information about a colorscheme:
[~,num,typ] = brewermap(0,'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:
N = 6;
set(0,'DefaultAxesColorOrder',brewermap(8,'Accent'))
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:
load spine
image(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'); % Set the default scheme.
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')

### Note ###

Compared to other functions available on MATLAB Exchange, this function:
- Consists of just one convenient M-file (No .mat files).
- Requires only the standard ColorBrewer scheme name to select the colorscheme.
- Supports all ColorBrewer colorschemes.
- Interplolates the complete palette for each scheme (eg. Diverging = 15 colors).
- Outputs the MATLAB standard N-by-3 numeric RGB array.
- Standard MATLAB default colormap length (same length as the current colormap).
- 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.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Updates
06 Feb 2014

- Add third output: colorscheme type as a string.
- Better input checking and error messages.

Contact us