-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated colorbrewer build and paths in driver.
- Loading branch information
Showing
11 changed files
with
305 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
function [colormap]=cbrewer(ctype, cname, ncol, interp_method) | ||
% | ||
% CBREWER - 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 | ||
% http://colorbrewer2.org/ | ||
% | ||
% The tables were generated from an MS-Excel file provided on the website | ||
% http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html | ||
% | ||
% | ||
% [colormap]=cbrewer(ctype, cname, ncol, interp_method) | ||
% | ||
% INPUT: | ||
% - ctype: type of color table 'seq' (sequential), 'div' (diverging), 'qual' (qualitative) | ||
% - cname: name of colortable. It changes depending on ctype. | ||
% - ncol: number of color in the table. It changes according to ctype and | ||
% cname | ||
% - interp_method: interpolation method (see interp1.m). Default is "cubic" ) | ||
% | ||
% A note on the number of colors: Based on the original data, there is | ||
% only a certain number of colors available for each type and name of | ||
% colortable. When 'ncol' is larger then the maximum number of colors | ||
% originally given, an interpolation routine is called (interp1) to produce | ||
% the "extended" colormaps. | ||
% | ||
% Example: To produce a colortable CT of ncol X 3 entries (RGB) of | ||
% sequential type and named 'Blues' with 8 colors: | ||
% CT=cbrewer('seq', 'Blues', 8); | ||
% To use this colortable as colormap, simply call: | ||
% colormap(CT) | ||
% | ||
% 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 (http://colorbrewer.org/). | ||
% | ||
% Author: Charles Robert | ||
% email: [email protected] | ||
% Date: 06.12.2011 | ||
% ------------------------------ | ||
% 18.09.2015 Minor fixes, fixed a bug where the 'spectral' color table did not appear in the preview | ||
|
||
|
||
% load colorbrewer data | ||
load('colorbrewer.mat') | ||
% initialise the colormap is there are any problems | ||
colormap=[]; | ||
if (~exist('interp_method', 'var')) | ||
interp_method='cubic'; | ||
end | ||
|
||
% If no arguments | ||
if (~exist('ctype', 'var') | ~exist('cname', 'var') | ~exist('ncol', 'var')) | ||
disp(' ') | ||
disp('[colormap] = cbrewer(ctype, cname, ncol [, interp_method])') | ||
disp(' ') | ||
disp('INPUT:') | ||
disp(' - ctype: type of color table *seq* (sequential), *div* (divergent), *qual* (qualitative)') | ||
disp(' - cname: name of colortable. It changes depending on ctype.') | ||
disp(' - ncol: number of color in the table. It changes according to ctype and cname') | ||
disp(' - interp_method: interpolation method (see interp1.m). Default is "cubic" )') | ||
|
||
disp(' ') | ||
disp('Sequential tables:') | ||
z={'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd',... | ||
'Purples','RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'Spectral'}; | ||
disp(z') | ||
|
||
disp('Divergent tables:') | ||
z={'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn'}; | ||
disp(z') | ||
|
||
disp(' ') | ||
disp('Qualitative tables:') | ||
%getfield(colorbrewer, 'qual') | ||
z={'Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3'}; | ||
disp(z') | ||
|
||
plot_brewer_cmap | ||
return | ||
end | ||
|
||
% Verify that the input is appropriate | ||
ctype_names={'div', 'seq', 'qual'}; | ||
if (~ismember(ctype,ctype_names)) | ||
disp('ctype must be either: *div*, *seq* or *qual*') | ||
colormap=[]; | ||
return | ||
end | ||
|
||
if (~isfield(colorbrewer.(ctype),cname)) | ||
disp(['The name of the colortable of type *' ctype '* must be one of the following:']) | ||
getfield(colorbrewer, ctype) | ||
colormap=[]; | ||
return | ||
end | ||
|
||
if (ncol>length(colorbrewer.(ctype).(cname))) | ||
% disp(' ') | ||
% disp('----------------------------------------------------------------------') | ||
% disp(['The maximum number of colors for table *' cname '* is ' num2str(length(colorbrewer.(ctype).(cname)))]) | ||
% disp(['The new colormap will be extrapolated from these ' num2str(length(colorbrewer.(ctype).(cname))) ' values']) | ||
% disp('----------------------------------------------------------------------') | ||
% disp(' ') | ||
cbrew_init=colorbrewer.(ctype).(cname){length(colorbrewer.(ctype).(cname))}; | ||
colormap=interpolate_cbrewer(cbrew_init, interp_method, ncol); | ||
colormap=colormap./255; | ||
return | ||
end | ||
|
||
if (isempty(colorbrewer.(ctype).(cname){ncol})) | ||
|
||
while(isempty(colorbrewer.(ctype).(cname){ncol})) | ||
ncol=ncol+1; | ||
end | ||
disp(' ') | ||
disp('----------------------------------------------------------------------') | ||
disp(['The minimum number of colors for table *' cname '* is ' num2str(ncol)]) | ||
disp('This minimum value shall be defined as ncol instead') | ||
disp('----------------------------------------------------------------------') | ||
disp(' ') | ||
end | ||
|
||
colormap=(colorbrewer.(ctype).(cname){ncol})./255; | ||
|
||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
% This script help produce a new 'jet'-like colormap based on other RGB reference colors | ||
|
||
% ------- I WAS ASKED --------------- | ||
% "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?"" | ||
% | ||
% ANSWER: | ||
% You should construct the new colormap based on the existing RGB values of 'jet' | ||
% but projecting these RGB values on your new RGB basis. | ||
% ----------------------------------- | ||
|
||
% load colormaps | ||
jet=colormap('jet'); | ||
RdBu=cbrewer('div', 'RdBu', 11); | ||
RdYlGn=cbrewer('div', 'RdYlGn', 11); | ||
|
||
% Define the new R, G, B references (p stands for prime) | ||
Rp=RdBu(1,:); | ||
Bp=RdBu(end, :); | ||
Gp=RdYlGn(end-2, :); | ||
RGBp=[Rp;Gp;Bp]; | ||
|
||
% construct the new colormap based on the existing RGB values of jet | ||
% Project the RGB values on your new basis | ||
newjet = jet*RGBp; | ||
|
||
% store data in a strcuture, easier to handle | ||
cmap.jet=jet; | ||
cmap.newjet=newjet; | ||
cnames={'jet', 'newjet'}; | ||
|
||
% plot the RGB values | ||
fh=figure(); | ||
colors={'r', 'g', 'b'}; | ||
for iname=1:length(cnames) | ||
subplot(length(cnames),1,iname) | ||
dat=cmap.(cnames{end-iname+1}); | ||
for icol=1:size(dat,2) | ||
plot(dat(:,icol), 'color', colors{icol}, 'linewidth', 2);hold on; | ||
end % icol | ||
title([' "' cnames{end-iname+1} '" in RGB plot']) | ||
end | ||
|
||
% plot the colormaps | ||
fh=figure(); | ||
for iname=1:length(cnames) | ||
F=cmap.(cnames{iname}); | ||
ncol=length(F); | ||
fg=1./ncol; % geometrical factor | ||
X=fg.*[0 0 1 1]; | ||
Y=0.1.*[1 0 0 1]+(2*iname-1)*0.1; | ||
|
||
for icol=1:ncol | ||
X2=X+fg.*(icol-1); | ||
fill(X2,Y,F(icol, :), 'linestyle', 'none') | ||
hold all | ||
end % icol | ||
text(-0.1, mean(Y), cnames{iname}, 'HorizontalAlignment', 'right', 'FontWeight', 'bold', 'FontSize', 10, 'FontName' , 'AvantGarde') | ||
xlim([-0.4, 1]) | ||
axis off | ||
set(gcf, 'color', [1 1 1]) | ||
ylim([0.1 1.05.*max(Y)]); | ||
end % iname | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
function [interp_cmap]=interpolate_cbrewer(cbrew_init, interp_method, ncolors) | ||
% | ||
% INTERPOLATE_CBREWER - interpolate a colorbrewer map to ncolors levels | ||
% | ||
% INPUT: | ||
% - cbrew_init: the initial colormap with format N*3 | ||
% - interp_method: interpolation method, which can be the following: | ||
% 'nearest' - nearest neighbor interpolation | ||
% 'linear' - bilinear interpolation | ||
% 'spline' - spline interpolation | ||
% 'cubic' - bicubic interpolation as long as the data is | ||
% uniformly spaced, otherwise the same as 'spline' | ||
% - ncolors=desired number of colors | ||
% | ||
% Author: Charles Robert | ||
% email: [email protected] | ||
% Date: 14.10.2011 | ||
|
||
|
||
% just to make sure, in case someone puts in a decimal | ||
ncolors=round(ncolors); | ||
|
||
% How many data points of the colormap available | ||
nmax=size(cbrew_init,1); | ||
|
||
% create the associated X axis (using round to get rid of decimals) | ||
a=(ncolors-1)./(nmax-1); | ||
X=round([0 a:a:(ncolors-1)]); | ||
X2=0:ncolors-1; | ||
|
||
z=interp1(X,cbrew_init(:,1),X2,interp_method); | ||
z2=interp1(X,cbrew_init(:,2),X2,interp_method); | ||
z3=interp1(X,cbrew_init(:,3),X2, interp_method); | ||
interp_cmap=round([z' z2' z3']); | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Copyright (c) 2015, Charles Robert | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the distribution | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
% Plots and identifies the various colorbrewer tables available. | ||
% Is called by cbrewer.m when no arguments are given. | ||
% | ||
% Author: Charles Robert | ||
% email: [email protected] | ||
% Date: 14.10.2011 | ||
|
||
|
||
|
||
load('colorbrewer.mat') | ||
|
||
ctypes={'div', 'seq', 'qual'}; | ||
ctypes_title={'Diverging', 'Sequential', 'Qualitative'}; | ||
cnames{1,:}={'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral'}; | ||
cnames{2,:}={'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd',... | ||
'Purples','RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd'}; | ||
cnames{3,:}={'Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', 'Set3'}; | ||
|
||
figure('position', [314 327 807 420]) | ||
for itype=1:3 | ||
|
||
%fh(itype)=figure(); | ||
subplot(1,3,itype) | ||
|
||
for iname=1:length(cnames{itype,:}) | ||
|
||
ncol=length(colorbrewer.(ctypes{itype}).(cnames{itype}{iname})); | ||
fg=1./ncol; % geometrical factor | ||
|
||
X=fg.*[0 0 1 1]; | ||
Y=0.1.*[1 0 0 1]+(2*iname-1)*0.1; | ||
F=cbrewer(ctypes{itype}, cnames{itype}{iname}, ncol); | ||
|
||
for icol=1:ncol | ||
X2=X+fg.*(icol-1); | ||
fill(X2,Y,F(icol, :), 'linestyle', 'none') | ||
text(-0.1, mean(Y), cnames{itype}{iname}, 'HorizontalAlignment', 'right', 'FontWeight', 'bold', 'FontSize', 10, 'FontName' , 'AvantGarde') | ||
xlim([-0.4, 1]) | ||
hold all | ||
end % icol | ||
%set(gca, 'box', 'off') | ||
title(ctypes_title{itype}, 'FontWeight', 'bold', 'FontSize', 16, 'FontName' , 'AvantGarde') | ||
axis off | ||
set(gcf, 'color', [1 1 1]) | ||
end % iname | ||
ylim([0.1 1.05.*max(Y)]); | ||
end %itype | ||
|
||
set(gcf, 'MenuBar', 'none') | ||
set(gcf, 'Name', 'ColorBrewer Color maps') |