-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviridis.m
More file actions
28 lines (26 loc) · 919 Bytes
/
viridis.m
File metadata and controls
28 lines (26 loc) · 919 Bytes
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
function C = viridis(n)
%VIRIDIS Compact viridis colormap (n×3). Works on any recent MATLAB.
% C = VIRIDIS() returns 256 colors.
% C = VIRIDIS(N) returns N colors.
%
% Stops taken from Matplotlib’s viridis and linearly interpolated.
if nargin==0 || isempty(n), n = 256; end
stops = [ ...
0.267004, 0.004874, 0.329415; % deep purple
0.282327, 0.094955, 0.417331;
0.253935, 0.265254, 0.529983;
0.206756, 0.371758, 0.553117;
0.163625, 0.471133, 0.558148;
0.128729, 0.566949, 0.550556;
0.134692, 0.658636, 0.517649;
0.266941, 0.748751, 0.440573;
0.477504, 0.821444, 0.318195;
0.741388, 0.873449, 0.149561;
0.993248, 0.906157, 0.143936]; % yellow-green
m = size(stops,1);
xi = linspace(1,m,n);
C = [interp1(1:m,stops(:,1),xi,'linear')', ...
interp1(1:m,stops(:,2),xi,'linear')', ...
interp1(1:m,stops(:,3),xi,'linear')'];
C = max(min(C,1),0); % clamp
end