load("data_Fig4.mat")

figure('Color', 'w', 'Units', 'normalized', 'Position', [0.1 0.3 0.8 0.55])
subplot(2,3,1)
imagesc(Espec/Up, cep_full, log10(abs(spec_dir_full.').^2))
xlim([0 15])
clim([-9 1])
colormap(cm_cpi)
hold on
plot(E_co_dir_full/Up, cep_full, 'Color', my_B, 'LineWidth', 1)
ylabel 'CEP (\pi)'
set(gca, 'FontSize', 14)

subplot(2,3,4)
imagesc(Espec/Up, cep_full, log10(abs(spec_rec_full.').^2))
xlim([0 15])
clim([-9 1])
colormap(cm_cpi)
hold on
plot(E_co_rec_full/Up, cep_full, 'Color', my_R, 'LineWidth', 1)
xlabel 'Energy (U_p)'
ylabel 'CEP (\pi)'
set(gca, 'FontSize', 14)

subplot(2,3,[2,3,5,6])
imagesc(Espec/Up, cep_full, log10(abs(spec_full.').^2))
xlim([0 15])
clim([-9 1])
colormap(cm_cpi)
hold on
plotContourLines(M_C, 'Color', [3 41 129]/255);
plotContourLines(M_pd, 'k');
xlabel 'Energy (U_p)'
ylabel 'CEP (\pi)'
set(gca, 'FontSize', 14)

function h = plotContourLines(in, varargin)

    if isa(in, 'matlab.graphics.chart.primitive.Contour')
        contourLines = contour2lines(in);
    elseif ismatrix(in) & size(in,1)==2
        contourLines = contour2lines(in);
    elseif isstruct(in)
        contourLines = in;
    else
        error('The input is not a valid data type. Must be a Contour handle or a Contour matrix of size (2,n).');
    end


    for l = 1:numel(contourLines)
        h(l) = plot(contourLines(l).x, contourLines(l).y, varargin{:}, 'DisplayName', num2str(contourLines(l).level));
        hold on;
    end
end
