Skip to content

Commit 7c3003e

Browse files
committed
updates to LUMIN interface; this is much better
1 parent 05c54d9 commit 7c3003e

File tree

2 files changed

+39
-35
lines changed

2 files changed

+39
-35
lines changed

colourscale.m

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
% best, although higher than this produces brighter colours they also
2525
% start clipping what is possible represent in RGB.
2626
%
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+
%
2734
% COLOURSCALE(...,'linewidth',[LW1 LW2])
2835
% If not specified, the plots take on their "natural" linewidth as default
2936
% or as specified by the user. If set to a two-element vector, the
@@ -34,7 +41,7 @@
3441
%
3542
% COLOURSCALE(...,'repeat',N)
3643
% 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
3845
% series, the first and fourth plot blue, the second and fifth
3946
% green, and the third and six red. The divisor of the number of
4047
% plots and the number of colour space repetitions must be an
@@ -43,11 +50,11 @@
4350
% COLOURSCALE(...,'permute',P)
4451
% By default the lines are coloured in the order in which they
4552
% 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])
4855
%
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.
5158
%
5259
% RGBOUT = colourscale( ... ) will simply return the colours that
5360
% would be used, but it will NOT attempt to colour the plot.
@@ -57,26 +64,24 @@
5764
% this package at the development repository:
5865
% <http://github.com/wspr/matlabpkg/>
5966
%
60-
% COLOURSCALEPLOT v0.1 Will Robertson
67+
% COLOURSCALE v0.1 Will Robertson
6168
% Licence appended.
6269

6370
p = inputParser;
6471
p.addOptional('hue',0.2);
6572
p.addOptional('chroma',70);
6673
p.addOptional('repeat',1);
6774
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]});
7076
p.addOptional('linewidth',[]);
7177

7278
p.parse(varargin{:});
7379

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;
8085
lw_range = p.Results.linewidth;
8186

8287
if ~isempty(lw_range)
@@ -85,7 +90,11 @@
8590
end
8691
end
8792

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');
8998

9099
Nch = length(ch);
91100
Ncol = Nch/series;
@@ -95,28 +104,23 @@
95104
error('There must be an integer multiple of specified data series in the figure.')
96105
end
97106

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);
112108

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);
115116

117+
% for linewidths we just do linear interpolation, no need for the indexing
118+
% as in the above:
116119
if ~isempty(lw_range)
117120
lw = linspace(lw_range(1),lw_range(2),Ncol);
118121
end
119122

123+
hcl = nan(Ncol,3);
120124
hcl(:,1) = hue*360;
121125
hcl(:,2) = chroma;
122126
hcl(:,3) = linspace(lmin,lmax,Ncol)';
@@ -142,19 +146,19 @@
142146
if isempty(lw_range)
143147
set(ch(permute(ii)),...
144148
'Color',rgb(ind,:),...
145-
'UserData','colourplot:ignore')
149+
'UserData','colourscale:ignore')
146150
else
147151
set(ch(permute(ii)),...
148152
'Color',rgb(ind,:),...
149153
'LineWidth',lw(ind),...
150-
'UserData','colourplot:ignore')
154+
'UserData','colourscale:ignore')
151155
end
152156
end
153157
if isequal(get(ch(ii),'type'),'surface')
154158
set(ch(permute(ii)),...
155159
'FaceColor',rgb(ind,:),...
156160
'EdgeColor',rgb(ind,:),...
157-
'UserData','colourplot:ignore')
161+
'UserData','colourscale:ignore')
158162
end
159163
end
160164
else

colourscale_test.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
xx = linspace(0,1,p);
5454
yy = repmat(1:l,[p 1])+rand(p,l);
5555
plot(xx,yy,'linewidth',2)
56-
colourscale('hue',hrange(c));
56+
colourscale('hue',hrange(c),'lumin',[1 99]);
5757
title(['H=',num2str(hrange(c))])
5858
axis tight
5959
end

0 commit comments

Comments
 (0)