clear all; clc
% model written by Allison Shaw (contact for assistance: ashaw@umn.edu)
% started April 2021
%   last updated: 10 January 2023
%
% plots two sets of simulations -- one where spatial sorting slows down spread,
% and one where spatial sorting speeds up spread.

load fig23sims.mat

fs1 = 10;  % axes labels
fs3 = 09;  % axis numbering
lw2 = 1; % fig edges
lw1 = 1.5; % figure lines

width = 5;
height = 9;
xpos = 3;
ypos = 2;
sx = 0.21;
sy = 0.10;
w = 0.72;
he = 0.35;
dy = 0.14;

c1 = [0.2 0.2 0.2]; % color 1
c2 = [0.6 0.6 0.6]; % color 2

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

axes('position',[sx sy+dy+he w he])
    plot(speed_with_lo,'color',c2,'LineWidth',lw1)
    hold on
    plot(speed_without_lo,'color',c1,'LineWidth',lw1)
    ylim([0 0.3])
    legend('with','without','location','southeast')
    ylabel('speed','fontsize',fs1)
    xlabel('time','fontsize',fs1)
    set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

axes('position',[sx sy w he])
    plot(speed_with_hi,'color',c2,'LineWidth',lw1)
    hold on
    plot(speed_without_hi,'color',c1,'LineWidth',lw1)
    ylim([0 0.3])
    ylabel('speed','fontsize',fs1)
    xlabel('time','fontsize',fs1)
	set(gca,'FontSize',fs3,'LineWidth',lw2,'Fontname', 'Arial');

% label subpanels
axes('position',[0 0 1 1],'visible','off')
hold on
     text(0.02,0.97,'a)')
     text(0.02,0.47,'b)')
     %
     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));

%print -dpdf -r600 Figure1.pdf
print -djpeg -r600 fig3.jpg
print -depsc fig3.eps

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