|
5 | 5 | % to each "line". These colours are a spectrum of saturations and intensities for
|
6 | 6 | % a given colour hue.
|
7 | 7 | %
|
8 |
| -% COLOURSCALE('hue',H) |
| 8 | +% COLOURSCALE(...,'hue',H) |
9 | 9 | % Use hue H for colour scheme. Since H is a standard "HSV" hue, it varies
|
10 | 10 | % from zero to one, where approximately:
|
11 | 11 | % H=0.0 - red
|
|
18 | 18 | % H=0.85 - magenta
|
19 | 19 | % H=1.0 - red again
|
20 | 20 | %
|
| 21 | +% COLOURSCALE(...,'chroma',C) |
| 22 | +% Use chroma C for colour scheme. Chroma appears to be a nonlinear |
| 23 | +% parameter with sensible maximum; values around 40 to 100 appear to be |
| 24 | +% best, although higher than this produces brighter colours they also |
| 25 | +% start clipping what is possible represent in RGB. |
| 26 | +% |
| 27 | +% COLOURSCALE(...,'linewidth',[LW1 LW2]) |
| 28 | +% If not specified, the plots take on their "natural" linewidth as default |
| 29 | +% or as specified by the user. If set to a two-element vector, the |
| 30 | +% linewidths of the lines will be set to vary linearly from LW1 to LW2 as |
| 31 | +% the plots change colour from dark to light. (This is useful as lighter |
| 32 | +% lines often need to be slightly thicker to remain visible compared to |
| 33 | +% darker lines.) |
| 34 | +% |
21 | 35 | % COLOURSCALE(...,'repeat',N)
|
22 | 36 | % An optional argument specifies the number of times to use the
|
23 | 37 | % colour space: e.g., colourplot(2) will turn, in a graph with 6 data
|
|
53 | 67 | p.addOptional('permute',[]);
|
54 | 68 | p.addOptional('lumin_min',[65 50 40 30]);
|
55 | 69 | p.addOptional('lumin_max',[65 80 80 90]);
|
56 |
| -p.addOptional('linewidth',[1 2]); |
| 70 | +p.addOptional('linewidth',[]); |
57 | 71 |
|
58 | 72 | p.parse(varargin{:});
|
59 | 73 |
|
|
64 | 78 | lumin_min = p.Results.lumin_min;
|
65 | 79 | lumin_max = p.Results.lumin_max;
|
66 | 80 | lw_range = p.Results.linewidth;
|
67 |
| -if numel(lw_range) == 1 |
68 |
| - lw_range = lw_range([1 1]); |
| 81 | + |
| 82 | +if ~isempty(lw_range) |
| 83 | + if numel(lw_range) == 1 |
| 84 | + lw_range = lw_range([1 1]); |
| 85 | + end |
69 | 86 | end
|
70 | 87 |
|
71 | 88 | ch = findobj(gca,'Type','line','-not','UserData','colourplot:ignore');
|
|
96 | 113 | lmin = lumin_min(min([Ncol,Nlum]));
|
97 | 114 | lmax = lumin_max(min([Ncol,Nlum]));
|
98 | 115 |
|
99 |
| -lw = linspace(lw_range(1),lw_range(2),Ncol); |
| 116 | +if ~isempty(lw_range) |
| 117 | + lw = linspace(lw_range(1),lw_range(2),Ncol); |
| 118 | +end |
100 | 119 |
|
101 | 120 | hcl(:,1) = hue*360;
|
102 | 121 | hcl(:,2) = chroma;
|
|
120 | 139 | for ii = 1:Nch
|
121 | 140 | ind = mod(ii-1,Ncol)+1;
|
122 | 141 | if isequal(get(ch(ii),'type'),'line')
|
123 |
| - set(ch(permute(ii)),... |
124 |
| - 'Color',rgb(ind,:),... |
125 |
| - 'LineWidth',lw(ind),... |
126 |
| - 'UserData','colourplot:ignore') |
| 142 | + if isempty(lw_range) |
| 143 | + set(ch(permute(ii)),... |
| 144 | + 'Color',rgb(ind,:),... |
| 145 | + 'UserData','colourplot:ignore') |
| 146 | + else |
| 147 | + set(ch(permute(ii)),... |
| 148 | + 'Color',rgb(ind,:),... |
| 149 | + 'LineWidth',lw(ind),... |
| 150 | + 'UserData','colourplot:ignore') |
| 151 | + end |
127 | 152 | end
|
128 | 153 | if isequal(get(ch(ii),'type'),'surface')
|
129 | 154 | set(ch(permute(ii)),...
|
|
176 | 201 | % Code written by Nicholas J. Hughes, 2014, released under the following
|
177 | 202 | % licence.
|
178 | 203 | %
|
| 204 | +% Some minor alternations by Will Robertson, 2018. |
| 205 | +% |
179 | 206 | % The MIT License (MIT)
|
180 | 207 | %
|
181 | 208 | % Copyright (c) 2014 Nicholas J. Hughes
|
|
236 | 263 | b = gamma_correct((0.055648*X - 0.204043*Y + 1.057311*Z)/WHITE_Y);
|
237 | 264 |
|
238 | 265 | % Round to integers and correct
|
239 |
| -r = round(255 * r); |
240 |
| -g = round(255 * g); |
241 |
| -b = round(255 * b); |
242 |
| -r(r > 255) = 255; |
243 |
| -r(r < 0) = 0; |
244 |
| -g(g > 255) = 255; |
245 |
| -g(g < 0) = 0; |
246 |
| -b(b > 255) = 255; |
247 |
| -b(b < 0) = 0; |
248 | 266 | rgb = [r, g, b];
|
| 267 | +rgb = round(255 * rgb); |
| 268 | + |
| 269 | +% if any(rgb(:) > 255) |
| 270 | +% warning('Colour outside RGB range; clipping.') |
| 271 | +% end |
| 272 | +% if any(rgb(:) < 0) |
| 273 | +% warning('Colour less than zero in RGB; clipping.') |
| 274 | +% end |
| 275 | + |
| 276 | +rgb(rgb(:) > 255) = 255; |
| 277 | +rgb(rgb(:) < 0) = 0; |
249 | 278 |
|
250 | 279 |
|
251 | 280 | function u = gamma_correct(u)
|
|
0 commit comments