|
1 | 1 |
|
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 |
4 | 4 | % This function takes the current figure and applies a series of colours
|
5 | 5 | % to each "line". These colours are a spectrum of saturations and intensities for
|
6 | 6 | % a given colour hue.
|
7 | 7 | %
|
8 |
| -% COLOURPLOT(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 |
| -% COLOURPLOT(C,N) |
| 21 | +% COLOURSCALE(...,'repeat',N) |
22 | 22 | % An optional argument specifies the number of times to use the
|
23 | 23 | % colour space: e.g., colourplot(2) will turn, in a graph with 6 data
|
24 | 24 | % series, the first and fourth plot blue, the second and fifth
|
25 | 25 | % green, and the third and six red. The divisor of the number of
|
26 | 26 | % plots and the number of colour space repetitions must be an
|
27 | 27 | % integer.
|
28 | 28 | %
|
29 |
| -% COLOURPLOT(C,N,PERMUTE) |
| 29 | +% COLOURSCALE(...,'permute',P) |
30 | 30 | % By default the lines are coloured in the order in which they
|
31 | 31 | % were plot. This order can be changed by specifying a permutation
|
32 | 32 | % of the order in the second argument, such as in a four-plot graph:
|
|
35 | 35 | % If the 'UserData' for a data line is 'colourplot:ignore', then
|
36 | 36 | % it will not be included in the COLOURPLOT colouring.
|
37 | 37 | %
|
38 |
| -% RGBOUT = colourplot( ... ) will simply return the colours that |
| 38 | +% RGBOUT = colourscale( ... ) will simply return the colours that |
39 | 39 | % would be used, but it will NOT attempt to colour the plot.
|
40 | 40 | %
|
41 | 41 | %
|
|
46 | 46 | % COLOURSCALEPLOT v0.1 Will Robertson
|
47 | 47 | % Licence appended.
|
48 | 48 |
|
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]); |
54 | 69 | end
|
55 | 70 |
|
56 | 71 | ch = findobj(gca,'Type','line','-not','UserData','colourplot:ignore');
|
|
71 | 86 | ncol1 = Ncol/2;
|
72 | 87 | ncol2 = Ncol/2;
|
73 | 88 | 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.') |
82 | 94 | end
|
83 | 95 |
|
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; |
86 | 103 | hcl(:,3) = linspace(lmin,lmax,Ncol)';
|
87 | 104 |
|
88 | 105 | rgb = nan(size(hcl));
|
|
91 | 108 | end
|
92 | 109 | rgb = rgb/255;
|
93 | 110 |
|
94 |
| -if nargin < 2 |
| 111 | +if isempty(permute) |
95 | 112 | permute = 1:Nch;
|
96 | 113 | else
|
97 | 114 | if ~isequal(sort(permute),1:Nch)
|
|
101 | 118 |
|
102 | 119 | if nargout == 0
|
103 | 120 | for ii = 1:Nch
|
| 121 | + ind = mod(ii-1,Ncol)+1; |
104 | 122 | 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),... |
106 | 126 | 'UserData','colourplot:ignore')
|
107 | 127 | end
|
108 | 128 | if isequal(get(ch(ii),'type'),'surface')
|
109 | 129 | 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,:),... |
112 | 132 | 'UserData','colourplot:ignore')
|
113 | 133 | end
|
114 | 134 | end
|
|
0 commit comments