Skip to content

Commit b3710f7

Browse files
committed
revise colourscaleplot
- change name slightly - add more options - add linewidth changes
1 parent 7e7db8b commit b3710f7

File tree

3 files changed

+104
-45
lines changed

3 files changed

+104
-45
lines changed

colourscaleplot.m renamed to colourscale.m

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
function [ RGBOUT ] = colourscaleplot( color , series , permute )
3-
%COLOURPLOT Make colourful, nice-looking plots
2+
function [ RGBOUT ] = colourscale( varargin )
3+
%COLOURSCALEPLOT Make colourful, nice-looking plots
44
% This function takes the current figure and applies a series of colours
55
% to each "line". These colours are a spectrum of saturations and intensities for
66
% a given colour hue.
77
%
8-
% COLOURPLOT(H)
8+
% COLOURSCALE('hue',H)
99
% Use hue H for colour scheme. Since H is a standard "HSV" hue, it varies
1010
% from zero to one, where approximately:
1111
% H=0.0 - red
@@ -18,15 +18,15 @@
1818
% H=0.85 - magenta
1919
% H=1.0 - red again
2020
%
21-
% COLOURPLOT(C,N)
21+
% COLOURSCALE(...,'repeat',N)
2222
% An optional argument specifies the number of times to use the
2323
% colour space: e.g., colourplot(2) will turn, in a graph with 6 data
2424
% series, the first and fourth plot blue, the second and fifth
2525
% green, and the third and six red. The divisor of the number of
2626
% plots and the number of colour space repetitions must be an
2727
% integer.
2828
%
29-
% COLOURPLOT(C,N,PERMUTE)
29+
% COLOURSCALE(...,'permute',P)
3030
% By default the lines are coloured in the order in which they
3131
% were plot. This order can be changed by specifying a permutation
3232
% of the order in the second argument, such as in a four-plot graph:
@@ -35,7 +35,7 @@
3535
% If the 'UserData' for a data line is 'colourplot:ignore', then
3636
% it will not be included in the COLOURPLOT colouring.
3737
%
38-
% RGBOUT = colourplot( ... ) will simply return the colours that
38+
% RGBOUT = colourscale( ... ) will simply return the colours that
3939
% would be used, but it will NOT attempt to colour the plot.
4040
%
4141
%
@@ -46,11 +46,26 @@
4646
% COLOURSCALEPLOT v0.1 Will Robertson
4747
% Licence appended.
4848

49-
if nargin < 2
50-
series = 1;
51-
end
52-
if nargin < 1
53-
color = 0.2;
49+
p = inputParser;
50+
p.addOptional('hue',0.2);
51+
p.addOptional('chroma',70);
52+
p.addOptional('repeat',1);
53+
p.addOptional('permute',[]);
54+
p.addOptional('lumin_min',[65 50 40 30]);
55+
p.addOptional('lumin_max',[65 80 80 90]);
56+
p.addOptional('linewidth',[1 2]);
57+
58+
p.parse(varargin{:});
59+
60+
hue = p.Results.hue;
61+
chroma = p.Results.chroma;
62+
series = p.Results.repeat;
63+
permute = p.Results.permute;
64+
lumin_min = p.Results.lumin_min;
65+
lumin_max = p.Results.lumin_max;
66+
lw_range = p.Results.linewidth;
67+
if numel(lw_range) == 1
68+
lw_range = lw_range([1 1]);
5469
end
5570

5671
ch = findobj(gca,'Type','line','-not','UserData','colourplot:ignore');
@@ -71,18 +86,20 @@
7186
ncol1 = Ncol/2;
7287
ncol2 = Ncol/2;
7388
end
74-
v1 = color/2; v2 = 1;
75-
76-
switch Ncol
77-
case 1, lmin = 65; lmax = 65;
78-
case 2, lmin = 50; lmax = 80;
79-
case 3, lmin = 40; lmax = 80;
80-
otherwise,
81-
lmin = 40; lmax = 85;
89+
v1 = hue/2; v2 = 1;
90+
91+
Nlum = numel(lumin_max);
92+
if numel(lumin_min) ~= numel(lumin_max)
93+
error('Min and max luminance vectors must be equal size.')
8294
end
8395

84-
hcl(:,1) = color*360;
85-
hcl(:,2) = 80;
96+
lmin = lumin_min(min([Ncol,Nlum]));
97+
lmax = lumin_max(min([Ncol,Nlum]));
98+
99+
lw = linspace(lw_range(1),lw_range(2),Ncol);
100+
101+
hcl(:,1) = hue*360;
102+
hcl(:,2) = chroma;
86103
hcl(:,3) = linspace(lmin,lmax,Ncol)';
87104

88105
rgb = nan(size(hcl));
@@ -91,7 +108,7 @@
91108
end
92109
rgb = rgb/255;
93110

94-
if nargin < 2
111+
if isempty(permute)
95112
permute = 1:Nch;
96113
else
97114
if ~isequal(sort(permute),1:Nch)
@@ -101,14 +118,17 @@
101118

102119
if nargout == 0
103120
for ii = 1:Nch
121+
ind = mod(ii-1,Ncol)+1;
104122
if isequal(get(ch(ii),'type'),'line')
105-
set(ch(permute(ii)),'Color',rgb(mod(ii-1,Ncol)+1,:),...
123+
set(ch(permute(ii)),...
124+
'Color',rgb(ind,:),...
125+
'LineWidth',lw(ind),...
106126
'UserData','colourplot:ignore')
107127
end
108128
if isequal(get(ch(ii),'type'),'surface')
109129
set(ch(permute(ii)),...
110-
'FaceColor',rgb(mod(ii-1,Ncol)+1,:),...
111-
'EdgeColor',rgb(mod(ii-1,Ncol)+1,:),...
130+
'FaceColor',rgb(ind,:),...
131+
'EdgeColor',rgb(ind,:),...
112132
'UserData','colourplot:ignore')
113133
end
114134
end

colourscale_test.m

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
%% Example of the COLOURSCALE function
2+
3+
%% Example of different number of plots
4+
5+
% number of plots to demo:
6+
M = 3;
7+
N = 3;
8+
9+
% points per graph:
10+
p = 20;
11+
12+
% colour: (0-1)
13+
H = 0.6;
14+
15+
% linewidths:
16+
LW = [2 4]; % more exaggerated than default
17+
18+
figure(1)
19+
for m = 1:M
20+
for n = 1:N
21+
c = N*(m-1)+n; % count from 1:N*M
22+
subplot(M,N,c); cla;
23+
xx = linspace(0,1,p);
24+
yy = repmat(1:c,[p 1])+rand(p,c);
25+
plot(xx,yy)
26+
colourscale('hue',H,'linewidth',LW);
27+
title(['Number of lines: ',num2str(c)])
28+
axis tight
29+
end
30+
end
31+
32+
%% Example across colours
33+
34+
% number of plots to demo:
35+
M = 4;
36+
N = 4;
37+
38+
% lines per graph:
39+
l = 5;
40+
41+
% points per line:
42+
p = 20;
43+
44+
hrange = linspace(0,1,M*N+1);
45+
hrange(end) = [];
46+
47+
figure(2)
48+
for m = 1:M
49+
for n = 1:N
50+
c = N*(m-1)+n; % count from 1:N*M
51+
subplot(M,N,c); cla;
52+
xx = linspace(0,1,p);
53+
yy = repmat(1:l,[p 1])+rand(p,l);
54+
plot(xx,yy,'linewidth',2)
55+
colourscale('hue',hrange(c));
56+
title(['H=',num2str(hrange(c))])
57+
axis tight
58+
end
59+
end

colourscaleplot_test.m

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)