|
24 | 24 | % best, although higher than this produces brighter colours they also
|
25 | 25 | % start clipping what is possible represent in RGB.
|
26 | 26 | %
|
| 27 | +% COLOURSCALE(...,'lumin',{[l_1 L_1] [l_2 L_2] ... [l_M L_M]}) |
| 28 | +% For N colours, use [l_N L_N] as the range for lumin values to vary over. |
| 29 | +% This approach isn't the most convenient for the user but allows the most |
| 30 | +% flexibility, as different lumin ranges appears best for different values |
| 31 | +% of N, and for different chroma/hue combinations. |
| 32 | +% If N>M then [l_M L_M] is used as the range. |
| 33 | +% |
27 | 34 | % COLOURSCALE(...,'linewidth',[LW1 LW2])
|
28 | 35 | % If not specified, the plots take on their "natural" linewidth as default
|
29 | 36 | % or as specified by the user. If set to a two-element vector, the
|
|
34 | 41 | %
|
35 | 42 | % COLOURSCALE(...,'repeat',N)
|
36 | 43 | % An optional argument specifies the number of times to use the
|
37 |
| -% colour space: e.g., colourplot(2) will turn, in a graph with 6 data |
| 44 | +% colour space: e.g., colourscale(2) will turn, in a graph with 6 data |
38 | 45 | % series, the first and fourth plot blue, the second and fifth
|
39 | 46 | % green, and the third and six red. The divisor of the number of
|
40 | 47 | % plots and the number of colour space repetitions must be an
|
|
43 | 50 | % COLOURSCALE(...,'permute',P)
|
44 | 51 | % By default the lines are coloured in the order in which they
|
45 | 52 | % were plot. This order can be changed by specifying a permutation
|
46 |
| -% of the order in the second argument, such as in a four-plot graph: |
47 |
| -% colourplot(1,[1 3 2 4]) |
| 53 | +% of the order using indexing, such as in a four-plot graph: |
| 54 | +% colourscale(...,'permute',[1 3 2 4]) |
48 | 55 | %
|
49 |
| -% If the 'UserData' for a data line is 'colourplot:ignore', then |
50 |
| -% it will not be included in the COLOURPLOT colouring. |
| 56 | +% If the 'UserData' for a data line is 'colourscale:ignore', then |
| 57 | +% it will not be included in the COLOURSCALE colouring. |
51 | 58 | %
|
52 | 59 | % RGBOUT = colourscale( ... ) will simply return the colours that
|
53 | 60 | % would be used, but it will NOT attempt to colour the plot.
|
|
57 | 64 | % this package at the development repository:
|
58 | 65 | % <http://github.com/wspr/matlabpkg/>
|
59 | 66 | %
|
60 |
| -% COLOURSCALEPLOT v0.1 Will Robertson |
| 67 | +% COLOURSCALE v0.1 Will Robertson |
61 | 68 | % Licence appended.
|
62 | 69 |
|
63 | 70 | p = inputParser;
|
64 | 71 | p.addOptional('hue',0.2);
|
65 | 72 | p.addOptional('chroma',70);
|
66 | 73 | p.addOptional('repeat',1);
|
67 | 74 | p.addOptional('permute',[]);
|
68 |
| -p.addOptional('lumin_min',[65 50 40 30]); |
69 |
| -p.addOptional('lumin_max',[65 80 80 90]); |
| 75 | +p.addOptional('lumin',{[65 65] [50 80] [40 80] [30 90]}); |
70 | 76 | p.addOptional('linewidth',[]);
|
71 | 77 |
|
72 | 78 | p.parse(varargin{:});
|
73 | 79 |
|
74 |
| -hue = p.Results.hue; |
75 |
| -chroma = p.Results.chroma; |
76 |
| -series = p.Results.repeat; |
77 |
| -permute = p.Results.permute; |
78 |
| -lumin_min = p.Results.lumin_min; |
79 |
| -lumin_max = p.Results.lumin_max; |
| 80 | +hue = p.Results.hue; |
| 81 | +chroma = p.Results.chroma; |
| 82 | +series = p.Results.repeat; |
| 83 | +permute = p.Results.permute; |
| 84 | +lumin = p.Results.lumin; |
80 | 85 | lw_range = p.Results.linewidth;
|
81 | 86 |
|
82 | 87 | if ~isempty(lw_range)
|
|
85 | 90 | end
|
86 | 91 | end
|
87 | 92 |
|
88 |
| -ch = findobj(gca,'Type','line','-not','UserData','colourplot:ignore'); |
| 93 | +if isnumeric(lumin) |
| 94 | + lumin = {lumin}; |
| 95 | +end |
| 96 | + |
| 97 | +ch = findobj(gca,'Type','line','-not','UserData','colourscale:ignore'); |
89 | 98 |
|
90 | 99 | Nch = length(ch);
|
91 | 100 | Ncol = Nch/series;
|
|
95 | 104 | error('There must be an integer multiple of specified data series in the figure.')
|
96 | 105 | end
|
97 | 106 |
|
98 |
| -hcl = ones(Ncol,3); |
99 |
| -if mod(Ncol,2) == 1 |
100 |
| - ncol1 = (Ncol+1)/2; |
101 |
| - ncol2 = (Ncol-1)/2; |
102 |
| -else |
103 |
| - ncol1 = Ncol/2; |
104 |
| - ncol2 = Ncol/2; |
105 |
| -end |
106 |
| -v1 = hue/2; v2 = 1; |
107 |
| - |
108 |
| -Nlum = numel(lumin_max); |
109 |
| -if numel(lumin_min) ~= numel(lumin_max) |
110 |
| - error('Min and max luminance vectors must be equal size.') |
111 |
| -end |
| 107 | +Nlum = numel(lumin); |
112 | 108 |
|
113 |
| -lmin = lumin_min(min([Ncol,Nlum])); |
114 |
| -lmax = lumin_max(min([Ncol,Nlum])); |
| 109 | +% indexing into lumin values needs a trick. |
| 110 | +% let's say we have lumin values of [65 50 40 30]; |
| 111 | +% for n=1, lumin=65; n=3, lumin=40; etc. |
| 112 | +% for n=6, the index is too high, so we want n=4, which is min([n,Nlum]): |
| 113 | +lumin_index = min([Ncol,Nlum]); |
| 114 | +lmin = lumin{lumin_index}(1); |
| 115 | +lmax = lumin{lumin_index}(2); |
115 | 116 |
|
| 117 | +% for linewidths we just do linear interpolation, no need for the indexing |
| 118 | +% as in the above: |
116 | 119 | if ~isempty(lw_range)
|
117 | 120 | lw = linspace(lw_range(1),lw_range(2),Ncol);
|
118 | 121 | end
|
119 | 122 |
|
| 123 | +hcl = nan(Ncol,3); |
120 | 124 | hcl(:,1) = hue*360;
|
121 | 125 | hcl(:,2) = chroma;
|
122 | 126 | hcl(:,3) = linspace(lmin,lmax,Ncol)';
|
|
142 | 146 | if isempty(lw_range)
|
143 | 147 | set(ch(permute(ii)),...
|
144 | 148 | 'Color',rgb(ind,:),...
|
145 |
| - 'UserData','colourplot:ignore') |
| 149 | + 'UserData','colourscale:ignore') |
146 | 150 | else
|
147 | 151 | set(ch(permute(ii)),...
|
148 | 152 | 'Color',rgb(ind,:),...
|
149 | 153 | 'LineWidth',lw(ind),...
|
150 |
| - 'UserData','colourplot:ignore') |
| 154 | + 'UserData','colourscale:ignore') |
151 | 155 | end
|
152 | 156 | end
|
153 | 157 | if isequal(get(ch(ii),'type'),'surface')
|
154 | 158 | set(ch(permute(ii)),...
|
155 | 159 | 'FaceColor',rgb(ind,:),...
|
156 | 160 | 'EdgeColor',rgb(ind,:),...
|
157 |
| - 'UserData','colourplot:ignore') |
| 161 | + 'UserData','colourscale:ignore') |
158 | 162 | end
|
159 | 163 | end
|
160 | 164 | else
|
|
0 commit comments