clear;clc;
%% 对CESM

load('wind10_JOFURO.mat')
load('SSTbar_OISST_WBC.mat')
load('OISST_Trend.mat')


FontSize = 13;
FontName = 'Times New Roman';
LW = 1.12;


hh1 = figure;
set(hh1,'position',[0 0 1000 700])

left_color = [0 0 0];
right_color = [0 0 0];
set(hh1,'defaultAxesColorOrder',[left_color;right_color]);


% 3 单纯只是画个轴 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pos1 = [0.15 0.2 0.7 0.4];
pos3 = pos1;
pos3(3) = pos3(3)+0.06;% [a,b,c,d],a和b是图片左下起始点坐标，c和d分别为宽和高。这里等于把轴3向右延长一部分
% pos3(1) = pos3(1)-0.06;
h3 = axes('position',pos3);
xlim1 = [0 17];
xlim3 = xlim1;
xlim3(2) = xlim3(1)+(xlim1(2)-xlim1(1))/pos1(3)*pos3(3);% 归到轴1上
set(h3,'xlim',xlim3,'xtick',[],'ylim',[0 6],'ycolor',[0,0,0],'color','none','YAxisLocation','right','FontSize',FontSize,'FontName',FontName);
box off
hold on
ylim3 = get(gca,'ylim');
plot([17,18.26],[0,0],'color',[1 1 0.99],'LineWidth',LW*2);





% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h1 = axes('Position',[0.15 0.2 0.7 0.4]);
yyaxis left

wind_KE= bar(1,wind10_KE,1,'Facecolor',[187 224 221]/255,'Edgecolor','k','Linewidth',0.5);hold on
wind_GS=bar(2,wind10_GS,1,'Facecolor',[247 201 216]/255,'Edgecolor','k','Linewidth',0.5);
wind_ARC=bar(3,wind10_ARC,1,'Facecolor',[190 186 219]/255,'Edgecolor','k','Linewidth',0.5);
wind_BC=bar(4,wind10_BC,1,'Facecolor',[249 243 191]/255,'Edgecolor','k','Linewidth',0.5);
% legend('KE','GS','ARC','BC')


errorbar(1,wind10_KE,0.23,'k.','Capsize',18);hold on
errorbar(2,wind10_GS,0.17,'k.','Capsize',18);
errorbar(3,wind10_ARC,0.2335,'k.','Capsize',18);
errorbar(4,wind10_BC,0.117,'k.','Capsize',18);


box on

xlim([0 17])
ylim([0 16])

set(gca,'xlim',[0 17],'xtick',[],...
    'ylim',[0 16],'ytick',0:2:16,'color','none','FontSize',FontSize,'FontName',FontName);
ylabel('$\overline U$ ($m\cdot$ $s^-$ $^1)$','Interpreter','latex')
% 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
yyaxis right

wind_KE= bar(7,mean(SST_KE_OISST,2),1,'Facecolor',[187 224 221]/255,'Edgecolor','k','Linewidth',0.5);hold on
wind_GS=bar(8,mean(SST_GS_OISST,2),1,'Facecolor',[247 201 216]/255,'Edgecolor','k','Linewidth',0.5);
wind_ARC=bar(9,mean(SST_ARC_OISST,2),1,'Facecolor',[190 186 219]/255,'Edgecolor','k','Linewidth',0.5);
wind_BC=bar(10,mean(SST_BC_OISST,2),1,'Facecolor',[249 243 191]/255,'Edgecolor','k','Linewidth',0.5);

errorbar(7,mean(SST_KE_OISST,2),std(SST_KE_OISST),'k.','Capsize',18);hold on
errorbar(8,mean(SST_GS_OISST,2),std(SST_GS_OISST),'k.','Capsize',18);
errorbar(9,mean(SST_ARC_OISST,2),std(SST_ARC_OISST),'k.','Capsize',18);
errorbar(10,mean(SST_BC_OISST,2),std(SST_BC_OISST),'k.','Capsize',18);


box on

xlim([0 17])
ylim([0 20])
ylabel(' $\overline S \overline S \overline T $ ($^\circ$C)','Interpreter','latex')
% plot 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pos3 = pos1;
h3 = axes('position',pos3);
wind_KE= bar(13,Trend_num_KE*100,1,'Facecolor',[187 224 221]/255,'Edgecolor','k','Linewidth',0.5);hold on
wind_GS=bar(14,Trend_num_GS*100,1,'Facecolor',[247 201 216]/255,'Edgecolor','k','Linewidth',0.5);
wind_ARC=bar(15,Trend_num_ARC*100,1,'Facecolor',[190 186 219]/255,'Edgecolor','k','Linewidth',0.5);
wind_BC=bar(16,Trend_num_BC*100,1,'Facecolor',[249 243 191]/255,'Edgecolor','k','Linewidth',0.5);

set(gca,'xlim',[0 17],...
    'ylim',[0 6],'ytick',[],'color','none','FontSize',FontSize,'FontName',FontName,'YAxisLocation','right');

ylabel('$\Delta$ $\overline S \overline S \overline T $ ($^\circ$C per Century)','Interpreter','latex','position',[19 2.9])

set(gca,'XTick',[2.5,8.5,14.5])
set(gca,'XTickLabel',[{'$\overline U$'},{'$\overline S \overline S \overline T$'},{'$\Delta$ $\overline S \overline S \overline T$'} ],'TickLabelInterpreter','latex')

p = patch([2 2.8 2.8 2],[5.2 5.2 5.6 5.6],[187 224 221]/255,'EdgeColor','k','LineWidth',0.3,'FaceAlpha',1); hold on;
text(3,5.43,'KE','color','k','FontSize',FontSize)
p = patch([6 6.8 6.8 6],[5.2 5.2 5.6 5.6],[247 201 216]/255,'EdgeColor','k','LineWidth',0.3,'FaceAlpha',1); hold on;
text(7,5.43,'GS','color','k','FontSize',FontSize)
p = patch([10 10.8 10.8 10],[5.2 5.2 5.6 5.6],[190 186 219]/255,'EdgeColor','k','LineWidth',0.3,'FaceAlpha',1); hold on;
text(11,5.43,'ARC','color','k','FontSize',FontSize)
p = patch([14 14.8 14.8 14],[5.2 5.2 5.6 5.6],[249 243 191]/255,'EdgeColor','k','LineWidth',0.3,'FaceAlpha',1); hold on;
text(15,5.43,'BC','color','k','FontSize',FontSize)
title('Background Condition in Observation')
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% print('-dpng','-loose','-r600','Figure_BeiBei');
text(-1,6.4,'d','FontSize',16,'FontWeight','bold')
