
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')


%% Define the colormap and limits
clear all
load('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_NR_tranAll,2))/fs - size(dF_NR_tranAll,2)/(2*fs);

% Plot the first subplot
fig1 = figure();
set(gcf,'Position',[100 100 700 500])
subplot(2,2,1)
imagesc(t, 1:size(dF_NR_tranAll,1), zscore(dF_NR_tranAll,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('Cell Number')
xlabel('Times from transit (s)')
ylabel('Transit number #')
title('NREM-REM')
xlim([-20 20])
ylim([1, size(dF_NR_tranAll,1)])
set(gca, 'YDir', 'normal')

% Plot the second subplot
subplot(2,2,2)
imagesc(t, 1:size(dF_NW_tranAll,1), zscore(dF_NW_tranAll,[],2))
clim(zlim)
colormap(cmap1)
colorbar
ylabel('Cell Number')
xlabel('Times from transit (s)')
ylabel('Transit number #')
title('NREM-WAKE')
xlim([-20 20])
ylim([1, size(dF_NW_tranAll,1)])
set(gca, 'YDir', 'normal')

% Plot the third subplot
subplot(2,2,3)
t1 = (1:size(dF_RW_tranAll,2))/fs - size(dF_RW_tranAll,2)/(2*fs);
imagesc(t1, 1:size(dF_RW_tranAll,1), zscore(dF_RW_tranAll,[],2));
clim(zlim)
colormap(cmap1)
colorbar
ylabel('Cell Number')
xlabel('Times from transit (s)')
ylabel('Transit number #')
title('REM-WAKE')
xlim([-20 20])
ylim([1, size(dF_RW_tranAll,1)])
set(gca, 'YDir', 'normal')
%%
subplot(2,2,4)
options.handle     = fig1;
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';
options.x_axis = (1:size(dF_NR_tranAll,2))/fs-size(dF_NR_tranAll,2)/(2*fs);
plot_areaerrorbar(zscore(dF_NR_tranAll,[],2),options)
hold on
options.x_axis = (1:size(dF_NW_tranAll,2))/fs-size(dF_NW_tranAll,2)/(2*fs);
options.color_area = [255 0 0]./255;  % red theme
options.color_line = [ 255 0 0]./255;
plot_areaerrorbar(zscore(dF_NW_tranAll,[],2),options)
subplot(2,2,4)
hold on
options.x_axis = (1:size(dF_RW_tranAll,2))/fs-size(dF_RW_tranAll,2)/(2*fs);
options.color_area = [0 0 0]./255;  
options.color_line = [ 0 0 0]./255;
plot_areaerrorbar(zscore(dF_RW_tranAll,[],2),options)
ylim([-2,2])
xlim([-20 20])

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