close all
% model written by Allison Shaw (contact for assistance: ashaw@umn.edu)
%   last updated: 16 June 2022

fs1 = 10;  % axes labels
fs3 = 09;  % axis numbering
lw2 = 1; % fig edges
lw1 = 1.5; % fig edges
msize = 25; % marker size

width = 11;
height = 12;
xpos = 3;
ypos = 2;
sx = 0.16;
sy = 0.15;
w = 0.35;
he = 0.2;
dx = 0.13;
dy = 0.09;

xx = 10; yy=5;

g1 = [0 0 0]; % black
g2 = [0.7 0.7 0.7]; % light grey
g3 = [0.5 0.5 0.5]; % med grey

figure(1); clf
hh = gcf;
set(hh,'PaperUnits','centimeters');
set(hh,'Units','centimeters');
set(gcf,'Position',[xpos ypos width height])

mymap = cool;
mymap = [1 1 1; mymap]; % set extreme low value to white
colormap(mymap)

load fig4_beta.mat
ind = [6 16 21];
axes('position',[sx sy+2*dy+2*he w he])
    imagesc(speed_FD2-speed_base,[-0.12 0.12])
    colorbar
    set(gca,'XTick',1:xx:length(nvec))
    set(gca,'XTickLabel',{nvec(1),'0',nvec(21)})
    set(gca,'YTick',1:yy:length(betavec))
    set(gca,'YTickLabel',betavec(1:yy:end))
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

axes('position',[sx+dx+w      sy+2*dy+2*he w he])
    imagesc(speed_FD1-speed_base,[-0.24 0.24])
    colorbar
    set(gca,'XTick',1:xx:length(nvec))
    set(gca,'XTickLabel',{nvec(1),'0',nvec(21)})
    set(gca,'YTick',1:yy:length(betavec))
    set(gca,'YTickLabel',betavec(1:yy:end))
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

%%
load fig4_v.mat
ind = [1 11 19];
axes('position',[sx      sy+dy+he w he])
    imagesc(speed_FD2-speed_base,[-0.12 0.12])
    colorbar
    set(gca,'XTick',1:xx:length(nvec))
    set(gca,'XTickLabel',{nvec(1),'0',nvec(21)})
    set(gca,'YTick',1:yy:length(vivec))
    set(gca,'YTickLabel',vivec(1:yy:end))
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

axes('position',[sx+dx+w sy+dy+he w he])
    imagesc(speed_FD1-speed_base,[-0.08 0.08])
    colorbar
    set(gca,'XTick',1:xx:length(nvec))
    set(gca,'XTickLabel',{nvec(1),'0',nvec(21)})
    set(gca,'YTick',1:yy:length(vivec))
    set(gca,'YTickLabel',vivec(1:yy:end))
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');


%%
load fig4_AE.mat

speed_base = repmat(speed_base_all',1,length(nvec));
speed_base(isnan(speed_base))=0;

ind = [1 2 3];
axes('position',[sx      sy w he])
    imagesc(speed_DD2-speed_base,[-0.06 0.06])
    colorbar
    set(gca,'XTick',1:xx:length(nvec))
    set(gca,'XTickLabel',{nvec(1),'0',nvec(21)})
    set(gca,'YTick',1:yy:length(avec))
    set(gca,'YTickLabel',avec(1:yy:end))
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');
    
axes('position',[sx+dx+w sy w he])
    imagesc(speed_DD1-speed_base,[-0.06 0.06])
    colorbar
    set(gca,'XTick',1:xx:length(nvec))
    set(gca,'XTickLabel',{nvec(1),'0',nvec(21)})
    set(gca,'YTick',1:yy:length(avec))
    set(gca,'YTickLabel',avec(1:yy:end))
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');


% label subpanels
axes('position',[0 0 1 1],'visible','off')
hold on
     text(0.06,     0.18+3*he+2*dy,'a)','horizontalalignment','center')
     text(0.06+w+dx,0.18+3*he+2*dy,'b)','horizontalalignment','center')
     text(0.06,     0.18+2*he+dy,'c)','horizontalalignment','center')
     text(0.06+w+dx,0.18+2*he+dy,'d)','horizontalalignment','center')
     text(0.06,     0.18+he,'e)','horizontalalignment','center')
     text(0.06+w+dx,0.18+he,'f)','horizontalalignment','center')
     %
     text(0.02,0.83,'transmission (\beta)','horizontalalignment','center','rotation',90)
     text(0.02,0.55,'dispersal (v)','horizontalalignment','center','rotation',90)
     text(0.02,0.25,'Allee threshold (a)','horizontalalignment','center','rotation',90)
     %
     text(0.3,0.05,{'symbiont net effect','(fecundity)'},'horizontalalignment','center')
     text(0.8,0.05,{'symbiont net effect','(survival)'},'horizontalalignment','center')
     set(gca,'FontSize',fs3,'Fontname', 'Arial');
axis([0 1 0 1])


% Backup previous settings
prePaperType = get(hh,'PaperType');
prePaperPosition = get(hh,'PaperPosition');
prePaperSize = get(hh,'PaperSize');

% Make changing paper type possible
set(hh,'PaperType','<custom>');
% Set the page size and position to match the figure's dimensions
position = get(hh,'Position');
set(hh,'PaperPosition',[0,0,position(3:4)]);
set(hh,'PaperSize',position(3:4));

%saveas(1,strcat(['fig3.jpg']))
%print -dpdf -r600 Figure_3.pdf
print -djpeg -r600 figS3.jpg

% Restore the previous settings
set(hh,'PaperType',prePaperType);
set(hh,'PaperPosition',prePaperPosition);
set(hh,'PaperSize',prePaperSize);
