Skip to content

Commit 4bd322b

Browse files
committed
documentation
1 parent e341ce6 commit 4bd322b

File tree

1 file changed

+71
-53
lines changed

1 file changed

+71
-53
lines changed

colourscale.m

Lines changed: 71 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
function [ RGBOUT ] = colourscale( varargin )
3-
%COLOURSCALEPLOT Make colourful, nice-looking plots
3+
%COLOURSCALE Make colourful, nice-looking plots
44
% This function takes the current figure and applies a series of colours
5-
% to each "line". These colours are a spectrum of saturations and intensities for
6-
% a given colour hue.
5+
% to each "line". These colours are a spectrum of saturations and
6+
% intensities for a given colour hue.
77
%
88
% COLOURSCALE(...,'hue',H)
9-
% Use hue H for colour scheme. Since H is a standard "HSV" hue, it varies
10-
% from zero to one, where approximately:
9+
% Use hue H for colour scheme (default 0.2).
10+
% H is a standard "HSV" hue, from zero to one, where approx.:
1111
% H=0.0 - red
1212
% H=0.1 - orange
1313
% H=0.15 - yellow
@@ -19,10 +19,11 @@
1919
% H=1.0 - red again
2020
%
2121
% COLOURSCALE(...,'chroma',C)
22-
% Use chroma C for colour scheme. Chroma appears to be a nonlinear
23-
% parameter with sensible maximum; values around 40 (dull) to 100 (bright)
24-
% appear to be best, although higher than this produces brighter colours
25-
% they also start clipping what is possible represent in RGB.
22+
% Use chroma C for colour scheme (default 70).
23+
% Chroma appears to be a nonlinear parameter with sensible maximum; values
24+
% around 40 (dull) to 100 (bright) appear to be best, although higher than
25+
% this produces brighter colours they also start clipping what is possible
26+
% represent in RGB.
2627
%
2728
% COLOURSCALE(...,'lumin',[l_N L_N])
2829
% Use [l_N L_N] as the range for lumin values to vary over. Lumin values
@@ -52,24 +53,30 @@
5253
% integer.
5354
%
5455
% COLOURSCALE(...,'permute',P)
55-
% By default the lines are coloured in the order in which they
56-
% were plot. This order can be changed by specifying a permutation
57-
% of the order using indexing, such as in a four-plot graph:
56+
% By default the lines are coloured in the order in which they were plot.
57+
% This order can be changed by specifying a permutation of the order using
58+
% indexing, such as in a four-plot graph:
5859
% colourscale(...,'permute',[1 3 2 4])
5960
%
60-
% If the 'UserData' for a data line is 'colourscale:ignore', then
61-
% it will not be included in the COLOURSCALE colouring.
61+
% If the 'UserData' for a data line is 'colourscale:ignore', then
62+
% it will not be included in the COLOURSCALE colouring.
6263
%
63-
% RGBOUT = colourscale( ... ) will simply return the colours that
64-
% would be used, but it will NOT attempt to colour the plot.
64+
% RGB = COLOURSCALE(...)
65+
% As above, and also returns the colours in an array.
66+
67+
68+
%% COLOURSCALE v0.1
6569
%
70+
% Copyright (c) 2017-2018 Will Robertson
71+
% All rights reserved.
72+
% Licence (BSD) appended.
6673
%
6774
% Please report bugs and feature requests for
6875
% this package at the development repository:
69-
% <http://github.com/wspr/matlabpkg/>
70-
%
71-
% COLOURSCALE v0.1 Will Robertson
72-
% Licence appended.
76+
% <http://github.com/wspr/matlab-plot-tools/>
77+
78+
79+
%% Option parsing
7380

7481
p = inputParser;
7582
p.addOptional('hue',0.2);
@@ -78,16 +85,18 @@
7885
p.addOptional('permute',[]);
7986
p.addOptional('lumin',{[65 65] [50 80] [40 80] [30 90]});
8087
p.addOptional('linewidth',[]);
81-
8288
p.parse(varargin{:});
8389

8490
hue = p.Results.hue;
8591
chroma = p.Results.chroma;
86-
series = p.Results.repeat;
92+
Nseries = p.Results.repeat;
8793
permute = p.Results.permute;
8894
lumin = p.Results.lumin;
8995
lw_range = p.Results.linewidth;
9096

97+
98+
%% Option massaging
99+
91100
if ~isempty(lw_range)
92101
if numel(lw_range) == 1
93102
lw_range = lw_range([1 1]);
@@ -100,15 +109,26 @@
100109

101110
ch = findobj(gca,'Type','line','-not','UserData','colourscale:ignore');
102111

103-
Nch = length(ch);
104-
Ncol = Nch/series;
112+
Nch = numel(ch);
113+
Ncol = Nch/Nseries;
114+
Nlum = numel(lumin);
115+
105116
if round(Ncol) ~= Ncol
106117
% Each set of data series must be the same length to avoid rounding problems!!
107118
disp(['There are ',num2str(Nch),' data series'])
108119
error('There must be an integer multiple of specified data series in the figure.')
109120
end
110121

111-
Nlum = numel(lumin);
122+
if isempty(permute)
123+
permute = 1:Nch;
124+
else
125+
if ~isequal(sort(permute),1:Nch)
126+
error('2nd argument must be a permutation of 1:N where N is the number of colours.');
127+
end
128+
end
129+
130+
131+
%% Calculate colours
112132

113133
% indexing into lumin values needs a trick.
114134
% let's say we have lumin values of [65 50 40 30];
@@ -135,44 +155,42 @@
135155
end
136156
rgb = rgb/255;
137157

138-
if isempty(permute)
139-
permute = 1:Nch;
140-
else
141-
if ~isequal(sort(permute),1:Nch)
142-
error('2nd argument must be a permutation of 1:N where N is the number of colours.');
143-
end
144-
end
145158

146-
if nargout == 0
147-
for ii = 1:Nch
148-
ind = mod(ii-1,Ncol)+1;
149-
if isequal(get(ch(ii),'type'),'line')
150-
if isempty(lw_range)
151-
set(ch(permute(ii)),...
152-
'Color',rgb(ind,:),...
153-
'UserData','colourscale:ignore')
154-
else
155-
set(ch(permute(ii)),...
156-
'Color',rgb(ind,:),...
157-
'LineWidth',lw(ind),...
158-
'UserData','colourscale:ignore')
159-
end
160-
end
161-
if isequal(get(ch(ii),'type'),'surface')
159+
%% Assign colours
160+
161+
for ii = 1:Nch
162+
ind = mod(ii-1,Ncol)+1;
163+
if isequal(get(ch(ii),'type'),'line')
164+
if isempty(lw_range)
165+
set(ch(permute(ii)),...
166+
'Color',rgb(ind,:),...
167+
'UserData','colourscale:ignore')
168+
else
162169
set(ch(permute(ii)),...
163-
'FaceColor',rgb(ind,:),...
164-
'EdgeColor',rgb(ind,:),...
170+
'Color',rgb(ind,:),...
171+
'LineWidth',lw(ind),...
165172
'UserData','colourscale:ignore')
166173
end
167174
end
168-
else
175+
if isequal(get(ch(ii),'type'),'surface')
176+
set(ch(permute(ii)),...
177+
'FaceColor',rgb(ind,:),...
178+
'EdgeColor',rgb(ind,:),...
179+
'UserData','colourscale:ignore')
180+
end
181+
end
182+
183+
184+
%% Fin
185+
186+
if nargout > 0
169187
RGBOUT = rgb;
170188
end
171189

172190
return
173191

174-
% Copyright (c) 2015-2016, Will Robertson, will at wspr dot io
175-
% All rights reserved.
192+
193+
%% Licence
176194
%
177195
% Distributed under the BSD licence in accordance with the wishes of the
178196
% Matlab File Exchange.

0 commit comments

Comments
 (0)