Calculations/Data-Analyzer/+Plotter/plotCumulants.m

93 lines
3.5 KiB
Matlab

function plotCumulants(scan_vals, cumulant_data, varargin)
%% plotCumulants: Plots the first four cumulants vs. a scan parameter
%
% Usage:
% plotCumulants(scan_vals, {mean_vals, var_vals, skew_vals, fourth_order_vals}, ...
% 'Title', 'My Title', ...
% 'FigNum', 1, ...
% 'FontName', 'Arial', ...
% 'MarkerSize', 6, ...
% 'LineWidth', 1.5, ...
% 'SkipSaveFigures', false, ...
% 'SaveFileName', 'cumulants.fig', ...
% 'SaveDirectory', pwd);
% --- Parse optional name-value pairs ---
p = inputParser;
addParameter(p, 'Title', '', @ischar);
addParameter(p, 'XLabel', 'Scan Parameter', @ischar);
addParameter(p, 'FigNum', 1, @(x) isnumeric(x) && isscalar(x));
addParameter(p, 'FontName', 'Arial', @ischar);
addParameter(p, 'MarkerSize', 6, @isnumeric);
addParameter(p, 'LineWidth', 1.5, @isnumeric);
addParameter(p, 'SkipSaveFigures', false, @islogical);
addParameter(p, 'SaveFileName', 'cumulants.fig', @ischar);
addParameter(p, 'SaveDirectory', pwd, @ischar);
parse(p, varargin{:});
opts = p.Results;
% --- Extract cumulant data ---
mean_vals = cumulant_data{1};
var_vals = cumulant_data{2};
skew_vals = cumulant_data{3};
fourth_order_vals = cumulant_data{4};
% --- Figure setup ---
fig = figure(opts.FigNum); clf;
set(fig, 'Color', 'w', 'Position', [100 100 950 750]);
axisFontSize = 14;
labelFontSize = 16;
titleFontSize = 16;
tLayout = tiledlayout(2,2,'TileSpacing','compact','Padding','compact');
% --- Mean ---
nexttile;
errorbar(scan_vals, mean_vals, sqrt(var_vals), 'o-', ...
'LineWidth', opts.LineWidth, 'MarkerSize', opts.MarkerSize);
title('Mean', 'FontSize', titleFontSize, 'FontWeight', 'bold');
xlabel(opts.XLabel, 'FontSize', labelFontSize);
ylabel('\kappa_1', 'FontSize', labelFontSize);
set(gca, 'FontSize', axisFontSize, 'FontName', opts.FontName);
grid on;
% --- Variance ---
nexttile;
plot(scan_vals, var_vals, 's-', 'LineWidth', opts.LineWidth, 'MarkerSize', opts.MarkerSize);
title('Variance', 'FontSize', titleFontSize, 'FontWeight', 'bold');
xlabel(opts.XLabel, 'FontSize', labelFontSize);
ylabel('\kappa_2', 'FontSize', labelFontSize);
set(gca, 'FontSize', axisFontSize, 'FontName', opts.FontName);
grid on;
% --- Skewness ---
nexttile;
plot(scan_vals, skew_vals, 'd-', 'LineWidth', opts.LineWidth, 'MarkerSize', opts.MarkerSize);
title('Skewness', 'FontSize', titleFontSize, 'FontWeight', 'bold');
xlabel(opts.XLabel, 'FontSize', labelFontSize);
ylabel('\kappa_3', 'FontSize', labelFontSize);
set(gca, 'FontSize', axisFontSize, 'FontName', opts.FontName);
grid on;
% --- Binder Cumulant ---
nexttile;
plot(scan_vals, fourth_order_vals, '^-', 'LineWidth', opts.LineWidth, 'MarkerSize', opts.MarkerSize);
title('Binder Cumulant', 'FontSize', titleFontSize, 'FontWeight', 'bold');
xlabel(opts.XLabel, 'FontSize', labelFontSize);
ylabel('\kappa_4', 'FontSize', labelFontSize);
set(gca, 'FontSize', axisFontSize, 'FontName', opts.FontName);
grid on;
% --- Super title ---
if ~isempty(opts.Title)
sgtitle(opts.Title, 'FontWeight', 'bold', 'FontSize', titleFontSize, 'Interpreter', 'latex');
end
% --- Save figure ---
Plotter.saveFigure(fig, ...
'SaveFileName', opts.SaveFileName, ...
'SaveDirectory', opts.SaveDirectory, ...
'SkipSaveFigures', opts.SkipSaveFigures);
end