-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_jet.m
64 lines (55 loc) · 1.84 KB
/
change_jet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
% 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