function plot_mu_compaction(map_final, scenario)
%PLOT_MU_COMPACTION Plot of the final mu and of the mu variation.
%
% To be called after the simulation, when map_final contains the map
% updated by update_friction_map.
%
% Each plot is shown in a separate figure window (no subplots) and is
% ALSO exported as a vector PDF into the thesis Images folder, ready to
% be included in the LaTeX document.
%
% Usage:
%   plot_mu_compaction(map_final, scenario)

    % Initial map taken from the original scenario
    map_initial = scenario.map;

    % Size check
    if ~isequal(size(map_final.mu), size(map_initial.mu))
        error('plot_mu_compaction: map_final.mu and scenario.map.mu have different sizes.');
    end

    % Delta mu
    delta_mu = map_final.mu - map_initial.mu;

    % --- Output folder for the thesis PDF figures -----------------------
    % Resolved relative to this function: project_swarm/latex_tesi_claude/Images
    here   = fileparts(mfilename('fullpath'));
    outdir = fullfile(here, '..', 'latex_tesi_claude', 'Images');
    if ~isfolder(outdir)
        outdir = here;   % fallback: save next to this function
        warning('plot_mu_compaction:outdir', ...
            'Thesis Images folder not found; saving PDFs in %s', outdir);
    end

    %% Figure 1 - Final mu after the vehicles pass
    f1 = figure('Name', 'Final mu - terrain compaction', 'NumberTitle', 'off', 'Color', 'w');
    imagesc(map_final.x, map_final.y, map_final.mu);
    set(gca,'YDir','normal');
    axis equal tight;
    colorbar;
    title('Final \mu after compaction');
    xlabel('x [m]');
    ylabel('y [m]');
    exportgraphics(f1, fullfile(outdir, 'terrain_mu_final.pdf'), 'ContentType', 'vector');

    %% Figure 2 - Delta mu
    f2 = figure('Name', 'Delta mu - terrain compaction', 'NumberTitle', 'off', 'Color', 'w');
    imagesc(map_final.x, map_final.y, delta_mu);
    set(gca,'YDir','normal');
    axis equal tight;
    colorbar;
    title('\Delta \mu = final \mu - initial \mu');
    xlabel('x [m]');
    ylabel('y [m]');
    exportgraphics(f2, fullfile(outdir, 'terrain_mu_delta.pdf'), 'ContentType', 'vector');

    fprintf('[plot_mu_compaction] PDF figures saved in: %s\n', outdir);

end
