
set(0, 'DefaultLineLineWidth', 2);
set(0,'defaultTextFontSize', 12);
set(0,'defaultAxesFontSize',12);
set(0,'DefaultFigureColormap',jet)
set(0,'defaultfigurecolor',[1 1 1])
set(0,'DefaultAxesTitleFontWeight', 'normal')
set(0, 'DefaultAxesFontName', 'Arial');
%% Define the colormap and limits
clear all
load('ACh_OXT_behaviorTrans.mat')
%%
zlim = [-3 3];
cmap1 = NegativeEnhancingColormap(32, zlim, [0 0 1], [1 0 0], [1 1 1], 1.25);

% Define the time axis
fs = 100;
t = (1:size(dF_NRtranAll.ACh,2))/fs - size(dF_NRtranAll.ACh,2)/(2*fs);

% Plot the first subplot
fig1 = figure();
set(gcf,'Position',[100 100 700 500])
subplot(2,3,1)
imagesc(t, 1:size(dF_NRtranAll.ACh,1), zscore(dF_NRtranAll.ACh,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('REM number #')
title('NREM-REM')
xlim([-20 20])
ylim([1, size(dF_NRtranAll.ACh,1)])
set(gca, 'YDir', 'normal')

subplot(2,3,4)
imagesc(t, 1:size(dF_NRtranAll.Oxt,1), zscore(dF_NRtranAll.Oxt,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('REM number #')
xlim([-20 20])
ylim([1, size(dF_NRtranAll.Oxt,1)])
set(gca, 'YDir', 'normal')


%% Plot the second subplot
t = (1:size(dF_RWtranAll.ACh,2))/fs - size(dF_RWtranAll.ACh,2)/(2*fs);
subplot(2,3,2)
imagesc(t, 1:size(dF_RWtranAll.ACh,1), zscore(dF_RWtranAll.ACh,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('trial number #')
title('REM-WAKE')
xlim([-20 20])
ylim([1, size(dF_RWtranAll.ACh,1)])
set(gca, 'YDir', 'normal')

subplot(2,3,5)
imagesc(t, 1:size(dF_RWtranAll.Oxt,1), zscore(dF_RWtranAll.Oxt,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('trial number #')
xlim([-20 20])
ylim([1, size(dF_RWtranAll.Oxt,1)])
set(gca, 'YDir', 'normal')

%% Plot the third subplot
t = (1:size(dF_NWtranAll.ACh,2))/fs - size(dF_NWtranAll.ACh,2)/(2*fs);
subplot(2,3,3)
imagesc(t, 1:size(dF_NWtranAll.ACh,1), zscore(dF_NWtranAll.ACh,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('trial number #')
title('NREM-WAKE')
xlim([-20 20])
ylim([65, size(dF_NWtranAll.ACh,1)])
set(gca, 'YDir', 'normal')

subplot(2,3,6)
imagesc(t, 1:size(dF_NWtranAll.Oxt,1), zscore(dF_NWtranAll.Oxt,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('trial number #')
xlim([-20 20])
ylim([65, size(dF_NWtranAll.Oxt,1)])
set(gca, 'YDir', 'normal')

exportgraphics(fig1,'Fig2B_DualColor.pdf','BackgroundColor','none','ContentType','vector')

%%
fs =100;
options.handle     =  figure();
options.color_area = [0 0 255]./255;    % Blue theme
options.color_line = [ 0 0 255]./255;
options.alpha      = 0.5;
options.line_width = 2;
options.error      = 'sem';
subplot(2,1,1)
options.x_axis = (1:size(dF_NRtranAll.ACh,2))/fs-size(dF_NRtranAll.ACh,2)/(2*fs);
plot_areaerrorbar(zscore(dF_NRtranAll.ACh,[],2),options)
hold on
options.x_axis = (1:size(dF_RWtranAll.ACh,2))/fs-size(dF_RWtranAll.ACh,2)/(2*fs);
options.color_area = [255 0 0]./255;  
options.color_line = [ 255 0 0]./255;
plot_areaerrorbar(zscore(dF_RWtranAll.ACh,[],2),options)
hold on
options.x_axis = (1:size(dF_NWtranAll.ACh,2))/fs-size(dF_NWtranAll.ACh,2)/(2*fs);
options.color_area = [0 0 0]./255;  
options.color_line = [ 0 0 0]./255;
plot_areaerrorbar(zscore(dF_NWtranAll.ACh,[],2),options)
ylim([-2,2])
xlim([-20 20])

subplot(2,1,2)
options.color_area = [0 0 255]./255;    % Blue theme
options.color_line = [ 0 0 255]./255;
options.x_axis = (1:size(dF_NRtranAll.Oxt,2))/fs-size(dF_NRtranAll.Oxt,2)/(2*fs);
plot_areaerrorbar(zscore(dF_NRtranAll.Oxt,[],2),options)
hold on
options.x_axis = (1:size(dF_RWtranAll.Oxt,2))/fs-size(dF_RWtranAll.Oxt,2)/(2*fs);
options.color_area = [255 0 0]./255;  
options.color_line = [ 255 0 0]./255;
plot_areaerrorbar(zscore(dF_RWtranAll.Oxt,[],2),options)
hold on
options.x_axis = (1:size(dF_NWtranAll.Oxt,2))/fs-size(dF_NWtranAll.Oxt,2)/(2*fs);
options.color_area = [0 0 0]./255;  
options.color_line = [ 0 0 0]./255;
plot_areaerrorbar(zscore(dF_NWtranAll.Oxt,[],2),options)
ylim([-2,2])
xlim([-20 20])
