-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage5_fig_scatterplots.m
216 lines (179 loc) · 8.78 KB
/
stage5_fig_scatterplots.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
% a5_fig_scatterpolots.m - script for generating plots used in paper.
% Manuscript Title: Variation in trends of consumption based carbon accounts
% Authors: Richard Wood, Daniel Moran, Konstantin Stadler, Joao Rodrigues
% Contact: [email protected]
% Git repo: https://github.com/rich-wood/CBCA
% Master script:
% MAIN.m
% Dependencies:
% compiled data from stage 3 (stage3_cf_harmonise_models.m) required
% Adidtional comments:
% Plot figure with all data points as a scatter plot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('results\cf_multimodel_normalised_results.mat','struct_results','meta')
% if you want to select a single year, do it here - note for these figures,
% only years between 36 and 56 make sense (there are more than 2 model
% observations)
year_select=logical(zeros(57,1)); %init
year_select(:)=1; % all years
% year_select(56)=1; % one year
%%%
% if you want to select a single country, do it here - note for these figures,
% only countries >9 are individual countries
country_select=logical(zeros(1,70)); %init
country_select(:)=1; % all countries
% country_select(11)=1; % one country
% there are 4 types of data intersted in here, PBCA, CBCA, both normalised and raw.
% Extract that data and arrange:
%obtain rsd, mean and number of observations
%meta.regions.unique_country - logical to extract individual country observations and not country aggregates:
tmp_norm_p_rsd=[struct_results.raw.p(meta.regions.unique_country).rsd];
tmp_p_mean=[struct_results.raw.p(meta.regions.unique_country).mean];
tmp_p_n=[struct_results.raw.p(meta.regions.unique_country).n];
%only plot sensible values (log transformation will occur) and when 3 data
%points
filterx=(tmp_norm_p_rsd)>=1e-5 & (tmp_p_n>2);
filterx(~year_select,:)=0;
filterx(:,~country_select)=0;
plot_p_y_raw=tmp_norm_p_rsd(filterx);
plot_p_x_raw=tmp_p_mean(filterx);
clear tmp*
tmp_raw_c_rsd=[struct_results.raw.c(meta.regions.unique_country).rsd];
tmp_raw_c_mean=[struct_results.raw.c(meta.regions.unique_country).mean];
tmp_raw_c_n=[struct_results.raw.c(meta.regions.unique_country).n];
filterx=(tmp_raw_c_rsd)>=1e-5 & (tmp_raw_c_n>2);
filterx(~year_select,:)=0;
filterx(:,~country_select)=0;
plot_c_y_raw=tmp_raw_c_rsd(filterx);
plot_c_x_raw=tmp_raw_c_mean(filterx);
clear tmp*
% set up x-values (on a log-spaced vector for plotting)
MIN_VALUE = 0.1;
MAX_VALUE = 1e5;
NUM_POINTS = 200;
xspace = logspace(log10(MIN_VALUE), log10(MAX_VALUE), NUM_POINTS);
% linear fit on log transformed data:
[pfit,gofp]=fit(log10(plot_p_x_raw),log10(plot_p_y_raw),'poly1');
[cfit,gofc]=fit(log10(plot_c_x_raw),log10(plot_c_y_raw),'poly1');
% obtain fitted line, based on log-spaced x values
pYraw=(pfit.p1.*((xspace)))+pfit.p2;
cYraw=(cfit.p1.*((xspace)))+cfit.p2;
pYraw_caption = [sprintf('y = %.2f x %.2f', pfit.p1, pfit.p2),sprintf(' R^{%d}',2),sprintf(': %.2f', gofp.rsquare)];
cYraw_caption = [sprintf('y = %.2f x %.2f', cfit.p1, cfit.p2),sprintf(' R^{%d}',2),sprintf(': %.2f', gofc.rsquare)];
% this time with normalised results as well.
%obtain rsd, mean and number of observations
%meta.regions.unique_country - logical to extract individual country observations and not country aggregates:
tmp_norm_p_rsd=[struct_results.norm.p(meta.regions.unique_country).rsd];
tmp_norm_p_mean=[struct_results.norm.p(meta.regions.unique_country).mean];
tmp_norm_p_n=[struct_results.norm.p(meta.regions.unique_country).n];
% tmp_norm_p_mean(1,:)=[];
% tmp_norm_p_n(1,:)=[];
%only plot sensible values (log transformation will occur) and when 3 data
%points
filterx=(tmp_norm_p_rsd)>=1e-5 & (tmp_norm_p_n>2);
filterx(~year_select,:)=0;
filterx(:,~country_select)=0;
plot_p_y_norm=tmp_norm_p_rsd(filterx);
plot_p_x_norm=tmp_norm_p_mean(filterx);
%CBCA values:
tmp_norm_c_rsd=[struct_results.norm.c(meta.regions.unique_country).rsd];
tmp_norm_c_mean=[struct_results.norm.c(meta.regions.unique_country).mean];
% tmp_norm_c_mean(1,:)=[];
filterx=(tmp_norm_c_rsd)>=1e-5;
filterx(~year_select,:)=0;
filterx(:,~country_select)=0;
plot_c_y_norm=tmp_norm_c_rsd(filterx);
plot_c_x_norm=tmp_norm_c_mean(filterx);
clear tmp*
[pfit,gofp]=fit(log10(plot_p_x_norm),log10(plot_p_y_norm),'poly1');
[cfit,gofc]=fit(log10(plot_c_x_norm),log10(plot_c_y_norm),'poly1');
pYnormalised=(pfit.p1.*((xspace)))+pfit.p2;
cYnormalised=(cfit.p1.*((xspace)))+cfit.p2;
pYnormalised_caption = [sprintf('y = %.2f x %.2f', pfit.p1, pfit.p2),sprintf(' R^{%d}',2),sprintf(': %.2f', gofp.rsquare)];
cYnormalised_caption = [sprintf('y = %.2f x %.2f', cfit.p1, cfit.p2),sprintf(' R^{%d}',2),sprintf(': %.2f', gofc.rsquare)];
%%
for which_plot=0:4
fig3 = figure;
hold on
% transform representation to log form
set(gca, 'XScale', 'log')
set(gca, 'YScale', 'log')
xtop=max(plot_c_x_raw+2000);
ylim([0.001,1])
xlim([1,xtop])
if which_plot==0
h1=scatter((plot_p_x_raw),(plot_p_y_raw)','.');
h5=scatter((plot_p_x_norm),(plot_p_y_norm),'+');
h3=plot(10.^xspace,10.^(pYraw),'b')
h7=plot(10.^xspace,10.^pYnormalised,'b--')
h2=scatter((plot_c_x_raw),(plot_c_y_raw)','x');
h6=scatter((plot_c_x_norm),(plot_c_y_norm),'*');
h4=plot(10.^xspace,10.^(cYraw),'r')
h8=plot(10.^xspace,10.^(cYnormalised),'r--')
end
if which_plot==1
h1=scatter((plot_p_x_raw),(plot_p_y_raw)','.');
h5=scatter((plot_p_x_norm),(plot_p_y_norm),'x');
h3=plot(10.^xspace,10.^(pYraw),'b')
h7=plot(10.^xspace,10.^pYnormalised,'r')
end
if which_plot==2
h2=scatter((plot_c_x_raw),(plot_c_y_raw)','.');
h6=scatter((plot_c_x_norm),(plot_c_y_norm),'x');
h4=plot(10.^xspace,10.^(cYraw),'b')
h8=plot(10.^xspace,10.^(cYnormalised),'r')
end
if which_plot==3
% plot the values, (axis is log-transformed above)
h1=scatter((plot_p_x_raw),(plot_p_y_raw)','.')
h2=scatter((plot_c_x_raw),(plot_c_y_raw)','x')
%plot exponents, as axis is transformed
h3=plot(10.^(xspace),10.^(pYraw),'b')
h4=plot(10.^(xspace),10.^(cYraw),'r')
end
if which_plot==4
% plot the values, (axis is log-transformed above)
h1=scatter((plot_p_x_norm),(plot_p_y_norm)','.')
h2=scatter((plot_c_x_norm),(plot_c_y_norm)','x')
%plot exponents, as axis is transformed
h3=plot(10.^(xspace),10.^(pYnormalised),'b')
h4=plot(10.^(xspace),10.^(cYnormalised),'r')
end
if which_plot==0
hleg1=legend([{'PBCA (raw)'}',{'CBCA (raw)'},{'PBCA (normalised)'}',{'CBCA (normalised)'},...
{'PBCA (raw)'},{'CBCA (raw)'},{'PBCA (normalised)'},{'CBCA (normalised)'}])
end
if which_plot==1
htit1=title([{'PBCA'}])
hleg1=legend([{'Raw'}',{'Normalised'}',...
{['Raw ']},{['Normalised ']}],'Location','Northeast','NumColumns',2)
annotation('textbox',[0.6, 0.6, 0.2, 0.1],'String', pYraw_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6);
annotation('textbox',[0.5, 0.35, 0.2, 0.1],'String', pYnormalised_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6);
end
if which_plot==2
hleg1=title([{'CBCA'}])
hleg1=legend([{'Raw'}',{'Normalised'}',...
{['Raw ']},{['Normalised ']}],'Location','Northeast','NumColumns',2)
annotation('textbox',[0.6, 0.62, 0.2, 0.1],'String', cYraw_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6);
annotation('textbox',[0.5, 0.4, 0.2, 0.1],'String', cYnormalised_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6)
end
if which_plot==3
hleg1=title([{'Normalised'}])
hleg1=legend([h1,h2,h3,h4],[{'PBCA'}',{'CBCA'},{'PBCA'},{'CBCA'}])
annotation('textbox',[0.5, mean(plot_p_y_raw)*5.5, 0.2, 0.1],'String', pYraw_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6);
annotation('textbox',[0.6, mean(plot_c_y_raw)*5.5, 0.2, 0.1],'String', cYraw_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6)
end
if which_plot==4
hleg1=title([{'Normalised'}])
hleg1=legend([h1,h2,h3,h4],[{'PBCA'}',{'CBCA'},{'PBCA'},{'CBCA'}])
annotation('textbox',[0.6, 0.3, 0.2, 0.1],'String', pYnormalised_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6);
annotation('textbox',[0.6, 0.55, 0.2, 0.1],'String', cYnormalised_caption, 'FontSize', 9, 'Color', 'k','BackgroundColor','w','EdgeColor','none','FaceAlpha',0.6)
end
xlabel('CO_2 (Gg)')
ylabel('Relative standard deviation ')
axis square
grid on
set(gcf,'color','w');
savefig(['figs\aScatter_',num2str(which_plot)])
print(['figs\aScatter_',num2str(which_plot)],'-djpeg')
end