File data_analysis/auxfunctions/plots/plotCorrelationMatrix.m changed (mode: 100644) (index e7caf5b..892219c) |
1 |
1 |
function plotCorrelationMatrix(cm, varargin) |
function plotCorrelationMatrix(cm, varargin) |
2 |
2 |
% plotCorrelationMatrix(cm, varargin) takes a covariance matrix cm and plots the entries of cm using a color encoding |
% plotCorrelationMatrix(cm, varargin) takes a covariance matrix cm and plots the entries of cm using a color encoding |
3 |
|
% possible varargin-arguments: |
|
4 |
|
% - 'log': use logscale for the color scale |
|
5 |
|
% - 'abs': plot the absolute values of the covariances |
|
6 |
|
% - a title can be specfied for the figure using the parameter-value pair: 'title', titlestring |
|
|
3 |
|
% |
|
4 |
|
% customization via key-value-pairs: |
|
5 |
|
% - 'log', true (default: false): use logscale for the color scale |
|
6 |
|
% - 'abs', true (default: false): plot the absolute values of the covariances |
|
7 |
|
% - 'title', title_string (default: ''): give the figure the title |
|
8 |
|
% title_string |
|
9 |
|
% - 'mute', true (default: false): switch off all text |
|
10 |
|
% - 'colormap', colormap (default: 'cool'): use colormap as colormap |
|
11 |
|
% - 'fontsize', fontsize (default: 4): use fontsize as fontsize |
7 |
12 |
|
|
8 |
13 |
%% default values |
%% default values |
9 |
|
mycolormap = 'cool'; |
|
10 |
|
mute = false; |
|
11 |
14 |
logscale = false; |
logscale = false; |
12 |
15 |
absvalues = false; |
absvalues = false; |
13 |
|
showtitle = false; |
|
|
16 |
|
|
|
17 |
|
title_string = ''; % no title by default |
|
18 |
|
show_labels = false; |
|
19 |
|
colormap = 'cool'; |
14 |
20 |
fontsize = 4; |
fontsize = 4; |
15 |
21 |
format = '%0.1e'; |
format = '%0.1e'; |
|
22 |
|
muted = false; |
16 |
23 |
|
|
17 |
|
for k=1:length(varargin) |
|
18 |
|
switch varargin{k} |
|
19 |
|
case '' |
|
20 |
|
|
|
21 |
|
case 'title' |
|
22 |
|
showtitle = true; |
|
23 |
|
titlestr = varargin{k+1}; |
|
24 |
|
varargin{k} = ''; |
|
25 |
|
varargin{k+1} = ''; |
|
26 |
|
case 'fontsize' |
|
27 |
|
fontsize = varargin{k+1} |
|
28 |
|
varargin{k} = ''; |
|
29 |
|
varargin{k+1} = ''; |
|
30 |
|
end |
|
31 |
|
end |
|
32 |
|
|
|
33 |
|
for k=1:length(varargin) |
|
|
24 |
|
for k=1:2:length(varargin) |
34 |
25 |
switch varargin{k} |
switch varargin{k} |
35 |
|
case 'log' |
|
36 |
|
logscale = true; |
|
37 |
|
case 'abs' |
|
38 |
|
absvalues = true; |
|
39 |
|
case 'mute' |
|
40 |
|
mute = true; |
|
41 |
|
fontsize = 0; |
|
42 |
|
format = '%0.0e'; |
|
43 |
|
case '' |
|
|
26 |
|
case {'abs', 'Abs'} |
|
27 |
|
absvalues = varargin{k+1}; |
|
28 |
|
case {'logscale', 'log', 'Log', 'Logscale', 'Log_scale'} |
|
29 |
|
logscale = varargin{k+1}; |
44 |
30 |
|
|
|
31 |
|
case {'title', 'title_string', 'Title', 'titlestring', 'Titlestring'} |
|
32 |
|
title_string = varargin{k+1}; |
|
33 |
|
case {'show_labels', 'labels', 'Labels', 'Show_labels'} |
|
34 |
|
show_labels = true; |
|
35 |
|
case {'colormap', 'Colormap'} |
|
36 |
|
colormap = varargin{k+1}; |
|
37 |
|
case {'fontsize', 'Fontsize'} |
|
38 |
|
fontsize = varargin{k+1}; |
|
39 |
|
case {'format', 'Format'} |
|
40 |
|
format = varargin{k+1}; |
|
41 |
|
case {'mute', 'Mute'} |
|
42 |
|
if varargin{k+1} |
|
43 |
|
muted = true |
|
44 |
|
elseif ismember(varargin{k+1}, {'true', 'True'}) |
|
45 |
|
muted = true; |
|
46 |
|
end |
|
47 |
|
|
45 |
48 |
otherwise |
otherwise |
46 |
49 |
error(['Unrecognized varargin-argument: ', varargin{k}]); |
error(['Unrecognized varargin-argument: ', varargin{k}]); |
47 |
50 |
end |
end |
|
... |
... |
end |
50 |
53 |
N = length(cm); |
N = length(cm); |
51 |
54 |
signmatrix = sign(cm); |
signmatrix = sign(cm); |
52 |
55 |
|
|
53 |
|
if mute |
|
54 |
|
labels = {}; |
|
55 |
|
else |
|
56 |
|
for k=1:N/4 |
|
|
56 |
|
if muted |
|
57 |
|
fontsize = 0; |
|
58 |
|
format = ''; %'%0.0e'; |
|
59 |
|
end |
|
60 |
|
|
|
61 |
|
if show_labels |
|
62 |
|
for k=1:N/4 |
57 |
63 |
labels{k} = ['q',num2str(k)]; |
labels{k} = ['q',num2str(k)]; |
58 |
64 |
labels{N/4 + k} = ['p',num2str(k)]; |
labels{N/4 + k} = ['p',num2str(k)]; |
59 |
65 |
labels{N/2 + k } = ['x',num2str(k)]; |
labels{N/2 + k } = ['x',num2str(k)]; |
60 |
66 |
labels{3*N/4 + k} = ['y',num2str(k)]; |
labels{3*N/4 + k} = ['y',num2str(k)]; |
61 |
67 |
end |
end |
|
68 |
|
else |
|
69 |
|
labels = {}; |
62 |
70 |
end |
end |
63 |
71 |
|
|
64 |
72 |
if absvalues |
if absvalues |
65 |
|
mycolormap = 'summer'; |
|
|
73 |
|
if isequal(colormap, 'cool') |
|
74 |
|
colormap = 'summer'; |
|
75 |
|
end |
|
76 |
|
% don't change colormap if a colormap was chose |
66 |
77 |
cm = abs(cm); |
cm = abs(cm); |
67 |
78 |
end |
end |
68 |
79 |
|
|
69 |
80 |
|
|
70 |
81 |
if logscale |
if logscale |
71 |
82 |
heatmap(cm, labels, labels,... |
heatmap(cm, labels, labels,... |
72 |
|
format,'Colormap', mycolormap,... |
|
|
83 |
|
format,'Colormap', colormap,... |
73 |
84 |
'UseLogColormap', true,... |
'UseLogColormap', true,... |
74 |
|
'FontSize', fontsize, 'Colorbar', {'SouthOutside'}, 'GridLines', ':'); |
|
|
85 |
|
'FontSize', fontsize,... |
|
86 |
|
'Colorbar', {'SouthOutside'}, 'GridLines', ':'); |
75 |
87 |
else |
else |
76 |
88 |
heatmap(cm, labels, labels,... |
heatmap(cm, labels, labels,... |
77 |
|
format,'Colormap', mycolormap,... |
|
78 |
|
'FontSize', fontsize, 'Colorbar', {'SouthOutside'}, 'GridLines', ':'); |
|
|
89 |
|
format,'Colormap', colormap,... |
|
90 |
|
'FontSize', fontsize,... |
|
91 |
|
'Colorbar', {'SouthOutside'}, 'GridLines', ':'); |
79 |
92 |
end |
end |
80 |
93 |
|
|
81 |
|
if showtitle |
|
82 |
|
title(titlestr) |
|
83 |
|
end |
|
|
94 |
|
title(title_string) |
84 |
95 |
|
|
85 |
|
end |
|