clear,clc
%%% plot the corr for different dataset
%%% by sfz 08-02-2016
%% load data
In_path='D:\Master\Paper\Weakening Coupling of PDO and NDVI\output_data\Move_corr\';
mo_path='D:\Master\Paper\Weakening Coupling of PDO and NDVI\o_images\';
load([In_path,'Mov_corr_NDVI_G(NAO)','.mat']);
load([In_path,'Mov_corr_NDVI_G(PDO)','.mat']);
%%% dataset of NDVI form 1980-2012
load([In_path,'Mov_R_Tring_PCA(NAO).mat']);
load([In_path,'Mov_R_Tring_PCA(PDO).mat']);
%%% dataset of tree ring form 1970-2001
% load([In_path,'Mov_R_npp_Gs(NAO).mat']);
% load([In_path,'Mov_R_npp_Gs(PDO).mat']);
%%% npp dataset of 7 modes from 1970-2010
load([In_path,'Mov_R_npp8_Gs(NAO).mat']);
load([In_path,'Mov_R_npp8_Gs(PDO).mat']);
%%% npp dataset of 8 modes from 1981-2010
year1=1970:(2001-15);
year1=year1';
% year2=1970:(2010-15);
% year2=year2';
year3=1982:(2010-15);
year3=year3';
npp8_Rp_M15=npp8_Rp_M15(2:end);
npp8_Rn_M15=npp8_Rn_M15(2:end);
year4=1982:(2012-15);
year4=year4';
%% 误差填充
%%%%%%%% Tring
std_Trp=std(Tring_Rp_PCA);
std_Trn=std(Tring_Rn_PCA);
Trp_up=Tring_Rp_PCA+0.5*std_Trp;
Trp_low=Tring_Rp_PCA-0.5*std_Trp;
Trn_up=Tring_Rn_PCA+0.5*std_Trn;
Trn_low=Tring_Rn_PCA-0.5*std_Trn;
x1ForFill=[year1;flipud(year1)];
Trp_Fill=[Trp_up;flipud(Trp_low)];
Trn_Fill=[Trn_up;flipud(Trn_low)];
%%%%%%%% NPP
std_NPp=std(npp8_Rp_M15);
std_NPn=std(npp8_Rn_M15);
NPp_up=npp8_Rp_M15+0.5*std_Trp;
NPp_low=npp8_Rp_M15-0.5*std_Trp;
NPn_up=npp8_Rn_M15+0.5*std_Trn;
NPn_low=npp8_Rn_M15-0.5*std_Trn;
x2ForFill=[year3;flipud(year3)];
NPp_Fill=[NPp_up;flipud(NPp_low)];
NPn_Fill=[NPn_up;flipud(NPn_low)];
%%%%%% NDVI
std_NVp=std(Rp_M15);
std_NVn=std(Rn_M15);
NVp_up=Rp_M15+0.5*std_Trp;
NVp_low=Rp_M15-0.5*std_Trp;
NVn_up=Rn_M15+0.5*std_Trn;
NVn_low=Rn_M15-0.5*std_Trn;
x3ForFill=[year4;flipud(year4)];
NVp_Fill=[NVp_up;flipud(NVp_low)];
NVn_Fill=[NVn_up;flipud(NVn_low)];
x=1982:1998;
e1= 0.426*ones(size(x));
e2= -0.426*ones(size(x));
%% fit
[m1,b1,Ynpp1,Rnpp1,Pnpp1]=line_Theilsen(year3,npp8_Rp_M15);
[m2,b2,Yndvi1,Rndvi1,Pndvi1]=line_Theilsen(year4,Rp_M15);
[m3,b3,Ynpp2,Rnpp2,Pnpp2]=line_Theilsen(year3,npp8_Rn_M15);
[m4,b4,Yndvi2,Rndvi2,Pndvi2]=line_Theilsen(year4,Rn_M15);
% Rndvi1=1-sum((Rp_M15-Yndvi1(:,2)).^2)/sum((Rp_M15-mean(Rp_M15)).^2)
%% plot
H1=figure(1);
set(H1,'position',[ 1 41 1600 783]);
ha = tight_subplot(1,2,[.01 .03],[.1 .01],[.01 .01]);
% set(H1,'position',[56 170 1494 525]);
axes(ha(1));
set(ha(1),'pos',[ 0.0681 0.1626 0.4062 0.7595]);
% hp1=plot(year1,Tring_Rp_PCA,'DisplayName','Tree ring','Color',[0 0 0],'LineWidth',1.8);
% hold on
% hh1=fill(x1ForFill,Trp_Fill,[0 0 0],'FaceAlpha',0.5,'EdgeAlpha',0.5,'EdgeColor',[0 0 0],'LineStyle','--');
% hold on
% plot(year2,npp_Rp_M15,'DisplayName','NPP7','Color',[0 0 1]);
% hold on
hp2=plot(year3,npp8_Rp_M15,'DisplayName','NPP8','Color',[138,43,226]./255,'LineWidth',1.2);
hold on
fill(x2ForFill,NPp_Fill,[138,43,226]./255,'FaceAlpha',0.5,'EdgeAlpha',0.5,'EdgeColor',[138,43,226]./255,'LineStyle','--');
hold on
plot(year3,Ynpp1,'Linestyle','-','Color',[138,43,226]./255,'LineWidth',1.2)
hold on
hp3=plot(year4,Rp_M15,'DisplayName','NDVI','Color',[255 69 0]./255,'LineWidth',1.2);
legend([hp2 hp3],'NPP8_G_S','NDVI_G_S')
hold on
fill(x3ForFill,NVp_Fill,[255 69 0]./255,'FaceAlpha',0.5,'EdgeAlpha',0.5,'EdgeColor',[255 69 0]./255,'LineStyle','--');
hold on
plot(year4,Yndvi1,'Linestyle','-','Color',[255 69 0]./255,'LineWidth',1.2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold on
plot(x,e1,'k--','LineWidth',1.0);
hold on
plot(x,e2,'k--','LineWidth',1.0);
hold on
H_pa = patch([1982,1982,1998,1998],[-0.426,0,0,-0.426],[.8 .8 .8]);
set(H_pa,'EdgeColor',[.8 .8 .8],'EdgeAlpha',0.5,'FaceAlpha',0.5)
y=zeros(1,1998-1982+1);
% plot(x,y,'k--','LineWidth',1.0);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
title('Sliding Correlation of PDO and Vegetation in TP(16)');
% xlabel('Starting Time');
xlim([1982 1998]); ylim([-0.8 0]);
ylabel('SR')
% set(gca ,'XTickLabel',{'1982','1984','1986','1988','1990','1992','1994','1996','1998';...
% '1997','1999','2001','2003','2005','2007','2009','2011','2013'});
set(get(gca,'XLabel'),'Fontname','Arial','FontSize',16,'FontWeight','bold');
set(get(gca,'YLabel'),'Fontname','Arial','FontSize',16,'FontWeight','bold');
set(get(gca,'TITLE'),'Fontname','Arial','FontSize',16,'FontWeight','bold');
set(gca,'fontsize',14,'Fontname','Arial','FontWeight','bold');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(ha(2));
set(ha(2),'pos',[0.5456 0.1626 0.4062 0.7595]);
% hn1=plot(year1,Tring_Rn_PCA,'DisplayName','Tree ring','Color',[0 0 0],'LineWidth',1.8);
% hold on
% fill(x1ForFill,Trn_Fill,[0 0 0],'FaceAlpha',0.5,'EdgeAlpha',1,'EdgeColor',[0 0 0],'LineStyle','--');
% hold on
% plot(year2,npp_Rn_M15,'DisplayName','NPP7','Color',[0 0 1]);
% hold on
hn2=plot(year3,npp8_Rn_M15,'DisplayName','NPP8','Color',[138,43,226]./255,'LineWidth',1.2);
hold on
fill(x2ForFill,NPn_Fill,[138,43,226]./255,'FaceAlpha',0.5,'EdgeAlpha',1,'EdgeColor',[138,43,226]./255,'LineStyle','--');
hold on
hn3=plot(year4,Rn_M15,'DisplayName','NDVI','Color',[255 69 0]./255,'LineWidth',1.2);
hold on
fill(x3ForFill,NVn_Fill,[255 69 0]./255,'FaceAlpha',0.5,'EdgeAlpha',1,'EdgeColor',[255 69 0]./255,'LineStyle','--');
hold on
plot(year4,Yndvi2,'Linestyle','-','Color',[1 0 0],'LineWidth',1.2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold on
plot(x,e1,'k--','LineWidth',1.0);
hold on
plot(x,e2,'k--','LineWidth',1.0);
hold on
H_pa = patch([1982,1982,1998,1998],[-0.426,0.426,0.426,-0.426],[.8 .8 .8]);
set(H_pa,'EdgeColor',[.8 .8 .8],'EdgeAlpha',0.5,'FaceAlpha',0.5)
hold on
plot(x,y,'k--','LineWidth',1.2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legend([hn2 hn3],'NPP8_G_S','NDVI_G_S')
title('Sliding Correlation of NAO and Vegetation in TP(16)');
% xlabel('Starting Time');
xlim([1982 1998]); ylim([-0.6 0.8]);
ylabel('SR')
set(get(gca,'XLabel'),'Fontname','Arial','FontSize',16,'FontWeight','bold');
set(get(gca,'YLabel'),'Fontname','Arial','FontSize',16,'FontWeight','bold');
set(get(gca,'TITLE'),'Fontname','Arial','FontSize',16,'FontWeight','bold');
set(gca,'Fontname','Arial','fontsize',14,'FontWeight','bold');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
legend1 = legend(ha(1),'show');
set(legend1,...
'Position',[0.410416667635242 0.856534697232779 0.0624999989010394 0.0632183890918205],...
'FontSize',12);
legend2 = legend(ha(2),'show');
set(legend2,...
'Position',[0.887291667635242 0.856534697232779 0.0624999989010394 0.0632183890918205],...
'FontSize',12);
% 创建 textbox
annotation(H1,'textbox',...
[0.525092202141899 0.951017153888681 0.0190803212851404 0.04],'String','b',...
'LineStyle','none',...
'FontSize',18,...
'Fontname','Arial',...
'FitBoxToText','off');
% 创建 textbox
annotation(H1,'textbox',...
[0.0437727576974565 0.951017153888681 0.0190803212851406 0.0400000000000003],...
'String',{'a'},...
'LineStyle','none',...
'FontSize',18,...
'Fontname','Arial',...
'FitBoxToText','off');
% 创建 textbox
annotation(H1,'textbox',...
[0.051 0.0884710744521633 0.033375 0.0383141762452108],'String','1997',...
'LineStyle','none',...
'FontWeight','bold',...
'FontSize',14,...
'Fontname','Arial',...
'FitBoxToText','off');
% 创建 textbox
annotation(H1,'textbox',...
[0.101625 0.0884710744