WIP büro
This commit is contained in:
260
Libs/cbrewer2/cbrewer2.m
Normal file
260
Libs/cbrewer2/cbrewer2.m
Normal file
@@ -0,0 +1,260 @@
|
||||
%CBREWER2 Interpolated versions of Cynthia Brewer's ColorBrewer colormaps
|
||||
% CBREWER2(CNAME, NCOL) returns the colour scheme CNAME with the number
|
||||
% of colours equal to NCOL. If there is a ColorBrewer scheme with exactly
|
||||
% this number of colours, the color scheme is returned as-is. If NCOL
|
||||
% larger (or smaller) than the designed colormaps for this scheme, the
|
||||
% largest (smallest) one is interpolated to provide enough colours,
|
||||
% unless the requested colour scheme CNAME is a qualitative palette. For
|
||||
% a qualitative scheme, the colours are repeated, cycling from the
|
||||
% beginning again, to output the requested NCOL colours.
|
||||
%
|
||||
% CBREWER2(CNAME) without an NCOL input will use the same number of
|
||||
% colours as the current colormap.
|
||||
%
|
||||
% CBREWER2(CNAME, NCOL, INTERP_METHOD) allows you to change the method
|
||||
% used for the interpolation. The default is 'cubic'.
|
||||
%
|
||||
% CBREWER2(CNAME, NCOL, INTERP_METHOD, INTERP_SPACE) allows you to
|
||||
% change the colorspace used for the interpolation. By default, this is
|
||||
% in the CIELAB colorspace, which is approximately perceptually uniform.
|
||||
% Options for INTERP_SPACE are
|
||||
% 'rgb' : interpolation in sRGB (as used in original CBREWER)
|
||||
% 'lab' : interpolation in CIELAB (default)
|
||||
% 'lch' : interpolation in CIELCH_ab (not recommended due to the
|
||||
% discontinuities at C=0 and H=0)
|
||||
% Anything else supported by COLORSPACE will also function.
|
||||
%
|
||||
% The input format CBREWER2(TYPE, ...) can also be used, where TYPE is
|
||||
% one of 'seq', 'div', 'qual'. This input is redandant and will be
|
||||
% ignored. This input format is provided for backwards compatibility with
|
||||
% the original CBREWER.
|
||||
%
|
||||
% Example 1 (sequential heatmap):
|
||||
% C = [0 2 4 6; 8 10 12 14; 16 18 20 22];
|
||||
% imagesc(C);
|
||||
% colorbar;
|
||||
% colormap(cbrewer('YlOrRd', 256);
|
||||
%
|
||||
% Example 2 (line plot):
|
||||
% x = 0:0.01:2;
|
||||
% sc = [0.5; 1; 2];
|
||||
% t0 = [0; 0.2; 0.4];
|
||||
% t = bsxfun(@rdivide, bsxfun(@plus, x, t0), sc);
|
||||
% y = sin(t * 2 * pi);
|
||||
% cmap = cbrewer2('Set1', numel(sc));
|
||||
% axes('ColorOrder', cmap, 'NextPlot', 'ReplaceChildren');
|
||||
% plot(x, y);
|
||||
%
|
||||
% Example 3 (divergent heatmap):
|
||||
% [X,Y,Z] = peaks(30);
|
||||
% surfc(X,Y,Z);
|
||||
% colormap(cbrewer2('RdBu'));
|
||||
%
|
||||
% This product includes color specifications and designs developed by
|
||||
% Cynthia Brewer (http://colorbrewer.org/). For more information on
|
||||
% ColorBrewer, please visit http://colorbrewer.org/.
|
||||
%
|
||||
% CBREWER2 uses a cached copy of the Cynthia Brewer color schemes which
|
||||
% was converted to .mat format by Charles Robert for use with CBREWER.
|
||||
% CBREWER is available from the MATLAB FileExchange under the MIT license.
|
||||
%
|
||||
% See also CBREWER, BREWERMAP, COLORSPACE, INTERP1.
|
||||
|
||||
|
||||
% Copyright (c) 2016 Scott Lowe
|
||||
%
|
||||
% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
% you may not use this file except in compliance with the License.
|
||||
% You may obtain a copy of the License at
|
||||
%
|
||||
% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%
|
||||
% Unless required by applicable law or agreed to in writing, software
|
||||
% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
% See the License for the specific language governing permissions and
|
||||
% limitations under the License.
|
||||
|
||||
|
||||
function colormap = cbrewer2(...
|
||||
cname, ncol, interp_method, interp_space, varargin)
|
||||
|
||||
% Definitions -------------------------------------------------------------
|
||||
|
||||
% List of all of Cynthia Brewer's colormaps and their types
|
||||
% seq: sequential
|
||||
% div: divergent
|
||||
% qual: qualitative
|
||||
cbdict = {...
|
||||
'Blues', 'seq'; ...
|
||||
'BuGn', 'seq'; ...
|
||||
'BuPu', 'seq'; ...
|
||||
'GnBu', 'seq'; ...
|
||||
'Greens', 'seq'; ...
|
||||
'Greys', 'seq'; ...
|
||||
'Oranges', 'seq'; ...
|
||||
'OrRd', 'seq'; ...
|
||||
'PuBu', 'seq'; ...
|
||||
'PuBuGn', 'seq'; ...
|
||||
'PuRd', 'seq'; ...
|
||||
'Purples', 'seq'; ...
|
||||
'RdPu', 'seq'; ...
|
||||
'Reds', 'seq'; ...
|
||||
'YlGn', 'seq'; ...
|
||||
'YlGnBu', 'seq'; ...
|
||||
'YlOrBr', 'seq'; ...
|
||||
'YlOrRd', 'seq'; ...
|
||||
'BrBG', 'div'; ...
|
||||
'PiYG', 'div'; ...
|
||||
'PRGn', 'div'; ...
|
||||
'PuOr', 'div'; ...
|
||||
'RdBu', 'div'; ...
|
||||
'RdGy', 'div'; ...
|
||||
'RdYlBu', 'div'; ...
|
||||
'RdYlGn', 'div'; ...
|
||||
'Spectral', 'div'; ...
|
||||
'Accent', 'qual'; ...
|
||||
'Dark2', 'qual'; ...
|
||||
'Paired', 'qual'; ...
|
||||
'Pastel1', 'qual'; ...
|
||||
'Pastel2', 'qual'; ...
|
||||
'Set1', 'qual'; ...
|
||||
'Set2', 'qual'; ...
|
||||
'Set3', 'qual'; ...
|
||||
};
|
||||
|
||||
|
||||
% Input handling ----------------------------------------------------------
|
||||
|
||||
narginchk(1, 5);
|
||||
|
||||
% Initialise variables if not supplied
|
||||
if nargin<2
|
||||
ncol = [];
|
||||
end
|
||||
if nargin<3
|
||||
interp_method = [];
|
||||
end
|
||||
if nargin<4
|
||||
interp_space = [];
|
||||
end
|
||||
if nargin<5
|
||||
varargin = {[]};
|
||||
end
|
||||
|
||||
% Check if the colormap type was unnecessarily input
|
||||
types = unique(cbdict(:, 2));
|
||||
if nargin > 1 && ischar(cname) && ischar(ncol)
|
||||
LI = ismember({cname ncol}, types);
|
||||
if ~any(LI); error('Number of colors cannot be a string'); end;
|
||||
if all(LI); error('Incorrect colormap name'); end;
|
||||
if LI(1)
|
||||
vgn = {cname; ncol; interp_method; interp_space};
|
||||
cname = vgn{2};
|
||||
ncol = vgn{3};
|
||||
interp_method = vgn{4};
|
||||
interp_space = varargin{1};
|
||||
ctype_input = vgn{1};
|
||||
elseif LI(2)
|
||||
vgn = {cname; ncol; interp_method; interp_space};
|
||||
cname = vgn{1};
|
||||
ncol = vgn{3};
|
||||
interp_method = vgn{4};
|
||||
interp_space = varargin{1};
|
||||
ctype_input = vgn{2};
|
||||
end
|
||||
else
|
||||
ctype_input = '';
|
||||
end
|
||||
|
||||
% Default values
|
||||
if isempty(ncol)
|
||||
% Number of colours in the colormap
|
||||
ncol = size(get(gcf,'colormap'), 1);
|
||||
end
|
||||
if isempty(interp_method)
|
||||
interp_method = 'pchip';
|
||||
end
|
||||
if isempty(interp_space)
|
||||
interp_space = 'lab';
|
||||
end
|
||||
|
||||
|
||||
% Load colorbrewer data ---------------------------------------------------
|
||||
Tmp = load('colorbrewer.mat');
|
||||
colorbrewer = Tmp.colorbrewer;
|
||||
|
||||
[TF, idict] = ismember(lower(cname), lower(cbdict(:, 1)));
|
||||
|
||||
if ~TF
|
||||
error('%s is not a recognised Brewer colormap',cname);
|
||||
end
|
||||
|
||||
cname = cbdict{idict, 1};
|
||||
ctype = cbdict{idict, 2};
|
||||
|
||||
if (~isfield(colorbrewer.(ctype), cname))
|
||||
error('Colormap %s is not present in loaded data',cname);
|
||||
end
|
||||
|
||||
|
||||
% Main script -------------------------------------------------------------
|
||||
|
||||
if ncol > length(colorbrewer.(ctype).(cname))
|
||||
% If we specified too many colours, we take the maximum and interpolate
|
||||
colormap = colorbrewer.(ctype).(cname){length(colorbrewer.(ctype).(cname))};
|
||||
colormap = colormap ./ 255;
|
||||
elseif isempty(colorbrewer.(ctype).(cname){ncol})
|
||||
% If we specified too few colours, we take the minimum and interpolate
|
||||
nmin = find(~cellfun(@isempty, colorbrewer.(ctype).(cname)), 1);
|
||||
colormap = colorbrewer.(ctype).(cname){nmin};
|
||||
colormap = colormap./255;
|
||||
else
|
||||
% If we specified a number of colours in the pre-designed range, no
|
||||
% need to interpolate
|
||||
colormap = (colorbrewer.(ctype).(cname){ncol}) ./ 255;
|
||||
return;
|
||||
end
|
||||
|
||||
% Don't interpolate if qualitative type
|
||||
if strcmp(ctype,'qual')
|
||||
if size(colormap, 1) >= ncol
|
||||
colormap = colormap(1:ncol, :);
|
||||
return;
|
||||
end
|
||||
warning('CBREWER2:QualTooManyColors', ...
|
||||
['Too many colors requested: cannot interpolate a qualitative' ...
|
||||
' colorscheme']);
|
||||
% Cycle the colours from the beginning again, so we have enough to
|
||||
% return
|
||||
colormap = repmat(colormap, ceil(ncol / size(colormap, 1)), 1);
|
||||
colormap = colormap(1:ncol, :);
|
||||
return;
|
||||
end
|
||||
|
||||
% Make sure we have colorspace downloaded from the FEX
|
||||
if ~strcmpi(interp_space, 'rgb') && ~exist('colorspace.m', 'file')
|
||||
P = requireFEXpackage(28790);
|
||||
if isempty(P);
|
||||
error(...
|
||||
['You need to download COLORSPACE from the MATLAB FEX and' ...
|
||||
' add it to the MATLAB path.']);
|
||||
end;
|
||||
end
|
||||
|
||||
% Move to perceptually uniform space
|
||||
if ~strcmpi(interp_space,'rgb')
|
||||
colormap = colorspace(['rgb->' interp_space], colormap);
|
||||
end
|
||||
|
||||
% Linearly interpolate
|
||||
X = linspace(0, 1, size(colormap, 1));
|
||||
XI = linspace(0, 1, ncol);
|
||||
colormap = interp1(X, colormap, XI, interp_method);
|
||||
|
||||
% Move from perceptually uniform space back to sRGB
|
||||
if ~strcmpi(interp_space,'rgb')
|
||||
colormap = colorspace(['rgb<-' interp_space], colormap);
|
||||
end
|
||||
|
||||
end
|
||||
BIN
Libs/cbrewer2/colorbrewer.mat
Normal file
BIN
Libs/cbrewer2/colorbrewer.mat
Normal file
Binary file not shown.
194
Libs/cbrewer2/requireFEXpackage.m
Normal file
194
Libs/cbrewer2/requireFEXpackage.m
Normal file
@@ -0,0 +1,194 @@
|
||||
function AddedPath = requireFEXpackage(FEXSubmissionID)
|
||||
%Function requireFEXpackage -
|
||||
%installs Matlab Central File Exchange (FEX) submission
|
||||
%with given ID into the directory chosen by the user.
|
||||
%A new FEX submissions may use previous FEX submissions as its part.
|
||||
%The function 'requireFEXpackage' helps in adding those previous
|
||||
%submissions to the user's MATLAB installation.
|
||||
%
|
||||
%This function is a part of File Exchange submission 31069.
|
||||
%Download the entire submission:
|
||||
%http://www.mathworks.com/matlabcentral/fileexchange/31069
|
||||
%
|
||||
% SYNTAX:
|
||||
% AddedPath = requireFEXpackage(FEXSubmissionID)
|
||||
%
|
||||
% INPUT:
|
||||
% ID of the required submission to File Exchange
|
||||
%
|
||||
% OUTPUT:
|
||||
% the path to that submission added to the user's MATLAB path.
|
||||
%
|
||||
% HOW TO CALL:
|
||||
% The command
|
||||
% P = requireFEXpackage(8277)
|
||||
% will download and install the package with ID 8277
|
||||
% (namely, nice 'fminsearchbnd' by John D'Errico)
|
||||
%
|
||||
% EXAMPLES -- HOW TO USE:
|
||||
%
|
||||
% EXAMPLE 1 (using 'exist' command):
|
||||
%
|
||||
% % first, somewhere in the very beginning of your code,
|
||||
% % check if the function 'fminsearchbnd' from the FEX package 8277
|
||||
% % is on your MATLAB path, and if it is not there,
|
||||
% % require the FEX package 8277:
|
||||
% if ~(exist('fminsearchbnd', 'file') == 2)
|
||||
% P = requireFEXpackage(8277); % fminsearchbnd is part of 8277
|
||||
% end
|
||||
%
|
||||
% % Then just use 'fminsearchbnd' where you need it:
|
||||
% syms x
|
||||
% RosenbrockBananaFunction = @(x) (1-x(1)).^2 + 100*(x(2)-x(1).^2).^2;
|
||||
% x = fminsearchbnd(RosenbrockBananaFunction,[3 3])
|
||||
|
||||
% EXAMPLE 2 (using 'try-catch' command):
|
||||
%
|
||||
% syms x
|
||||
% RosenbrockBananaFunction = @(x) (1-x(1)).^2+100*(x(2)-x(1).^2).^2;
|
||||
% try
|
||||
% % if function 'fminsearchbnd' already exists in your MATLAB
|
||||
% % installation, just use it:
|
||||
% x = fminsearchbnd(RosenbrockBananaFunction,[3 3])
|
||||
% catch
|
||||
% % if function 'fminsearchbnd' is not present in your MATLAB
|
||||
% % installation, first get the package 8277 (to which it belongs)
|
||||
% % from the MATLAB Central File Exchange (FEX)
|
||||
% P = requireFEXpackage(8277); % fminsearchbnd is part of 8277
|
||||
% % and then use that function:
|
||||
% x = fminsearchbnd(RosenbrockBananaFunction,[3 3])
|
||||
% end
|
||||
%
|
||||
%
|
||||
% NOTE: on Mac platform, the title of the dialog box for
|
||||
% choosing the directory for installing the required FEX package
|
||||
% is not shown; this is not a bug, this is how UIGETDIR works on Macs --
|
||||
% see the documentation for UIGETDIR
|
||||
% http://www.mathworks.com/help/techdoc/ref/uigetdir.html
|
||||
%
|
||||
% (C) Igor Podlubny, 2011
|
||||
|
||||
% Copyright (c) 2011, Igor Podlubny
|
||||
% 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.
|
||||
|
||||
|
||||
ID = num2str(FEXSubmissionID);
|
||||
|
||||
% Ask user for the confirmation of the installation
|
||||
% of the required FEX package
|
||||
yes = ['YES, Install package ' ID];
|
||||
no = 'NO, do not install';
|
||||
userchoice = questdlg(['The Matlab function/toolbox, which you are running, ' ...
|
||||
'requires the presence of the package ' ID ...
|
||||
' from Matlab Central File Exchange.' ...
|
||||
sprintf('\n\n') ...
|
||||
'Would you like to install the FEX package ' ID ' now?'] , ...
|
||||
['Required package ' ID], ...
|
||||
yes, no, yes);
|
||||
|
||||
% Handle response
|
||||
switch userchoice
|
||||
case yes,
|
||||
install = 1;
|
||||
case no,
|
||||
install = 0;
|
||||
otherwise,
|
||||
install = 0;
|
||||
end
|
||||
|
||||
|
||||
if install == 1
|
||||
baseURL = 'http://www.mathworks.com/matlabcentral/fileexchange/';
|
||||
query = '?download=true';
|
||||
|
||||
location = uigetdir(pwd, ['Select the directory for installing the required FEX package' ID ]);
|
||||
if location ~= 0
|
||||
% download package 'ID' from Matlab Central File Exchange
|
||||
filetosave = [location filesep ID '.zip'];
|
||||
FEXpackage = [baseURL ID query];
|
||||
[f,status] = urlwrite(FEXpackage,filetosave);
|
||||
if status==0
|
||||
warndlg(['No connection to Matlab Central File Exchange,' ' or package ' ID ' does not exist.' ...
|
||||
' Package ' ID ' has not been installed. ' ...
|
||||
' Check you internet settings and the ID of the required package, and try again. '] , ...
|
||||
['No connection to Matlab Central File Exchange' ' or package ' ID ' does not exist'], ...
|
||||
'modal');
|
||||
AddedPath = '';
|
||||
return
|
||||
end
|
||||
% unzip the downloaded file to the subdirectory 'ID'
|
||||
todir = [location filesep ID];
|
||||
% if the directory 'ID' doesn't exist at given location, create it
|
||||
if ~(exist([location filesep ID], 'dir') == 7)
|
||||
mkdir(location, ID);
|
||||
end
|
||||
try
|
||||
unzip(filetosave, todir);
|
||||
% after unzipping, delete the downloaded ZIP file
|
||||
delete(filetosave);
|
||||
% prepend the paths to the downloaded package to the MATLAB path
|
||||
P = genpath([location filesep ID]);
|
||||
path(P,path);
|
||||
catch
|
||||
% if the FEX package is not ZIP, then it is a single m-file
|
||||
% just move the file to the ID directory
|
||||
[pathstr, name, ext] = fileparts(filetosave);
|
||||
movefile(filetosave, [todir filesep name '.m']);
|
||||
P = genpath([location filesep ID]);
|
||||
path(P,path);
|
||||
end
|
||||
else
|
||||
P = '';
|
||||
end
|
||||
|
||||
AddedPath = P;
|
||||
else
|
||||
AddedPath = '';
|
||||
end
|
||||
|
||||
|
||||
if install == 1,
|
||||
% Ask user about reviewing and saving the modified MATLAB path,
|
||||
% and take him to PATHTOOL, if the user wants to save the modified path
|
||||
yes = 'YES, I want to review and save the MATLAB path';
|
||||
no = 'NO, I don''t want to save the path permanently';
|
||||
userchoice = questdlg(['After adding the package ' ID ...
|
||||
' from Matlab Central File Exchange to your MATLAB installation,' ...
|
||||
' the MATLAB path has been modified accordingly. ', ...
|
||||
'Would you like to review and save the modified MATLAB path?'] , ...
|
||||
'Review and save the modified MATLAB path for future use?', ...
|
||||
yes, no, yes);
|
||||
|
||||
% Handle response
|
||||
switch userchoice
|
||||
case yes,
|
||||
pathtool;
|
||||
case no,
|
||||
otherwise,
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user