82 lines
2.9 KiB
Matlab
82 lines
2.9 KiB
Matlab
function plotPDF(dataCell, referenceValues, varargin)
|
|
%% plotPDF: Plots 2D heatmap of PDFs for grouped data
|
|
%
|
|
% Usage:
|
|
% Plotter.plotPDF(dataCell, referenceValues, ...
|
|
% 'Title', 'My Title', ...
|
|
% 'XLabel', 'Scan Parameter', ...
|
|
% 'YLabel', 'Data Values', ...
|
|
% 'FigNum', 1, ...
|
|
% 'FontName', 'Arial', ...
|
|
% 'SkipSaveFigures', true, ...
|
|
% 'SaveFileName', 'SavedPDFs', ...
|
|
% 'SaveDirectory', 'results', ...
|
|
% 'NumPoints', 200, ...
|
|
% 'DataRange', [min max], ...
|
|
% 'XLim', [xmin xmax], ...
|
|
% 'Colormap', @jet);
|
|
|
|
% --- Parse optional inputs ---
|
|
p = inputParser;
|
|
addParameter(p, 'Title', '', @(x) ischar(x) || isstring(x));
|
|
addParameter(p, 'XLabel', '', @(x) ischar(x) || isstring(x));
|
|
addParameter(p, 'YLabel', '', @(x) ischar(x) || isstring(x));
|
|
addParameter(p, 'FigNum', 1, @(x) isscalar(x));
|
|
addParameter(p, 'FontName', 'Arial', @ischar);
|
|
addParameter(p, 'FontSize', 14, @isnumeric);
|
|
addParameter(p, 'SkipSaveFigures', false, @islogical);
|
|
addParameter(p, 'SaveFileName', 'pdf.fig', @ischar);
|
|
addParameter(p, 'SaveDirectory', pwd, @ischar);
|
|
addParameter(p, 'NumPoints', 200, @(x) isscalar(x));
|
|
addParameter(p, 'DataRange', [], @(x) isempty(x) || numel(x)==2);
|
|
addParameter(p, 'XLim', [], @(x) isempty(x) || numel(x)==2);
|
|
addParameter(p, 'Colormap', @jet);
|
|
parse(p, varargin{:});
|
|
opts = p.Results;
|
|
|
|
N_params = numel(referenceValues);
|
|
|
|
% --- Determine y-grid for PDF ---
|
|
if isempty(opts.DataRange)
|
|
allData = cell2mat(dataCell(:));
|
|
y_grid = linspace(min(allData), max(allData), opts.NumPoints);
|
|
else
|
|
y_grid = linspace(opts.DataRange(1), opts.DataRange(2), opts.NumPoints);
|
|
end
|
|
|
|
pdf_matrix = zeros(numel(y_grid), N_params);
|
|
|
|
% --- Compute PDFs ---
|
|
for i = 1:N_params
|
|
data = dataCell{i};
|
|
data = data(~isnan(data));
|
|
if isempty(data), continue; end
|
|
f = ksdensity(data, y_grid);
|
|
pdf_matrix(:, i) = f;
|
|
end
|
|
|
|
% --- Plot heatmap ---
|
|
fig = figure(opts.FigNum); clf(fig);
|
|
set(fig, 'Color', 'w', 'Position',[100 100 950 750]);
|
|
|
|
imagesc(referenceValues, y_grid, pdf_matrix);
|
|
set(gca, 'YDir', 'normal', 'FontName', opts.FontName, 'FontSize', opts.FontSize);
|
|
xlabel(opts.XLabel, 'Interpreter', 'latex', 'FontSize', opts.FontSize, 'FontName', opts.FontName);
|
|
ylabel(opts.YLabel, 'Interpreter', 'latex', 'FontSize', opts.FontSize, 'FontName', opts.FontName);
|
|
title(opts.Title, 'Interpreter', 'latex', 'FontSize', opts.FontSize + 2, 'FontWeight', 'bold');
|
|
colormap(feval(opts.Colormap));
|
|
c = colorbar;
|
|
ylabel(c, 'PDF', 'Interpreter', 'latex', 'FontSize', opts.FontSize);
|
|
|
|
if ~isempty(opts.XLim)
|
|
xlim(opts.XLim);
|
|
end
|
|
|
|
% --- Save figure ---
|
|
Plotter.saveFigure(fig, ...
|
|
'SaveFileName', opts.SaveFileName, ...
|
|
'SaveDirectory', opts.SaveDirectory, ...
|
|
'SkipSaveFigures', opts.SkipSaveFigures);
|
|
|
|
end
|