-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparityplot.m
142 lines (132 loc) · 3.88 KB
/
parityplot.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function parityplot(yactual,ypred,plottype,NV)
arguments
yactual double
ypred double
plottype char {mustBeMember(plottype,{'hex','scatter'})} = 'hex'
NV.xunits char = '$J m^{-2}$'
NV.yunits char = '$J m^{-2}$'
NV.xname char = 'actual GBE'
NV.yname char = 'predicted GBE'
NV.title char = ''
NV.charlbl char = ''
NV.sz(1,1) int32 = 36
NV.c double = [0 0 1]
NV.mkr char = 'o'
NV.fillQ(1,1) logical = false
NV.scatterOpts(1,1) struct = struct()
NV.reflineOpts(1,1) struct = struct()
NV.Interpreter char {mustBeMember(NV.Interpreter,{'tex','latex','none'})} = 'latex'
NV.FontSize int32 = 11
NV.legend = {'off'}
NV.Location char = 'northwest'
NV.cblbl char = 'counts'
NV.cbnds double = []
NV.cscale char {mustBeMember(NV.cscale,{'log','linear'})} = 'log'
NV.res(1,1) double = 50
NV.drawEdges(1,1) logical = 0
NV.showZeros(1,1) logical = 0
NV.xlim = [min([yactual(:);ypred(:)]) max([yactual(:);ypred(:)])]
NV.ylim = [min([yactual(:);ypred(:)]) max([yactual(:);ypred(:)])]
NV.axis = 'equal'
end
% PARITYPLOT Create a parity plot and pass options to (scatter() or hexscatter()) and refline().
%--------------------------------------------------------------------------
% Author(s): Sterling Baird
%
% Date: 2020-09-03
%
% Inputs:
% y1 - x-axis data
%
% y2 - y-axis data
%
% NV - name-value pairs
% scatter-specific
% 'sz', 'c', 'mkr', 'fillQ', 'scatterOpts'
% refline-specific
% 'reflineOpts'
% xlabel/ylabel/title/legend -specific
% 'Interpreter', 'FontSize', 'legend', 'Location'
%
% Outputs:
% ax - handle to axis
%
% Usage:
% parityplot(y1,y2);
%
% Dependencies:
% *
%
% Notes:
% See also: SCATTER, REFLINE
%
% Look at arguments ... end in function to see classes and defaults for
% name-value pairs
%--------------------------------------------------------------------------
assert(all(size(ypred)==size(yactual)),['y1 [' num2str(size(ypred)) '] and y2 [' num2str(size(yactual)) '] should be same size'])
switch plottype
case 'hex'
hexscatter(yactual,ypred,NV.xlim,NV.ylim,'cscale',NV.cscale,'cbnds',NV.cbnds,'axis',NV.axis);
case 'scatter'
%% scatter
if NV.fillQ
% ax1 = plot(yactual,ypred,NV.mkr);
ax1 = scatter(yactual,ypred,NV.sz,NV.c,NV.mkr,'filled');
else
% ax1 = plot(yactual,ypred,NV.mkr);
ax1 = scatter(yactual,ypred,NV.sz,NV.c,NV.mkr);
end
if ~isempty(NV.c) && (size(NV.c,1) ~= 1)
cb = colorbar;
cb.Label.Interpreter = 'latex';
cb.Label.String = NV.cblbl;
end
scatterNames = fields(NV.scatterOpts);
for i = 1:length(scatterNames)
scatterName = scatterNames{i};
ax1.(scatterName) = NV.scatterOpts.(scatterName);
end
end
%% refline
hold on
ax2 = refline(1,0);
reflineNames = fields(NV.reflineOpts);
for i = 1:length(reflineNames)
reflineName = reflineNames{i};
ax2.(reflineName) = NV.reflineOpts.(reflineName);
end
axis square tight
%% axes
if ~isempty(NV.xunits)
xunits = ['(',NV.xunits,')'];
else
xunits = '';
end
if ~isempty(NV.yunits)
yunits = ['(',NV.yunits,')'];
else
yunits = '';
end
xlbl = strjoin({NV.xname,xunits},' ');
ylbl = strjoin({NV.yname,yunits},' ');
xlabel(xlbl,'Interpreter',NV.Interpreter,'FontSize',NV.FontSize)
ylabel(ylbl,'Interpreter',NV.Interpreter,'FontSize',NV.FontSize)
title(NV.title,'Interpreter',NV.Interpreter,'FontSize',NV.FontSize)
% legend
lgd = legend(NV.legend{:},'Interpreter',NV.Interpreter);
if ~isempty(lgd)
lgd.Location = NV.Location;
end
% label for figure tiles, e.g. '(a)', '(b)', '(c)', '(d)'
if ~isempty(NV.charlbl)
text(0.025,0.95,NV.charlbl,'Units','normalized','FontSize',12,'Interpreter',NV.Interpreter)
end
if ~isempty(NV.xlim)
xlim(NV.xlim)
end
if ~isempty(NV.ylim)
ylim(NV.ylim)
end
% colormap jet
hold off
end