72 lines
2.9 KiB
Matlab
72 lines
2.9 KiB
Matlab
function fig_config(customConfig)
|
|
% setFigureDefaults Sets default properties for all figures
|
|
%
|
|
% Usage:
|
|
% fig_config() % Applies default settings
|
|
% fig_config(userConfig) % Overrides defaults with userConfig
|
|
|
|
%% Define default settings
|
|
% In IEEETran, \textwidth is 7.1413 inches
|
|
% - Use `\printinunitsof{in}\prntlen{\textwidth}`
|
|
% - To output the \textwidth value in the generated document,
|
|
% you need to use the `printlen` and `layouts` packages.
|
|
textwidth_inches = 7.1413;
|
|
|
|
% Set the figure width to 0.5 times \textwidth and define the aspect ratio (16:9 or 4:3)
|
|
aspect = 16/9; % Aspect ratio (can also use 4/3)
|
|
axes_width = 0.75;
|
|
axes_hight = 0.75;
|
|
axes_pos = [0.15, 0.15, axes_width, axes_hight];
|
|
fig_width = 0.5 * textwidth_inches;
|
|
fig_hight = (fig_width * axes_width / aspect) / axes_hight;
|
|
|
|
defaultConfig = struct( ...
|
|
'defaultFigureUnits', 'inches', ...
|
|
'defaultFigurePosition', [0, 0, fig_width, fig_hight], ...
|
|
'defaultAxesPosition', axes_pos, ...
|
|
'defaultFigurePaperPositionMode', 'manual', ...
|
|
'defaultFigurePaperUnits', 'inches', ...
|
|
'defaultFigurePaperPosition', [0, 0, fig_width, fig_hight], ...
|
|
'defaultFigurePaperSize', [fig_width, fig_hight], ...
|
|
'defaultLineLineWidth', 0.5, ... % -- Line and marker
|
|
'defaultLineMarkerSize', 3, ...
|
|
'defaultAxesFontName', 'Times New Roman', ... % -- Fonts
|
|
'defaultTextFontName', 'Times New Roman', ...
|
|
'defaultLegendFontName', 'Times New Roman', ...
|
|
'defaultAxesLabelFontSizeMultiplier', 1.15, ...
|
|
'defaultAxesFontSize', 7, ...
|
|
'defaultTextFontSize', 10, ...
|
|
'defaultLegendFontSize', 7, ...
|
|
'defaultTextInterpreter', 'latex', ... % -- Interpreter
|
|
'defaultAxesTickLabelInterpreter', 'latex', ...
|
|
'defaultLegendInterpreter', 'latex', ...
|
|
'defaultAxesGridColor', [0.15, 0.15, 0.15], ... % -- Grid
|
|
'defaultAxesGridAlpha', 0.25, ...
|
|
'defaultAxesGridLineStyle', ':', ...
|
|
'defaultAxesGridLineWidth', 0.5, ...
|
|
'defaultArrowshapeHeadWidth', 6, ... % -- Arrow
|
|
'defaultArrowshapeHeadLength', 6 ...
|
|
);
|
|
|
|
% Merge user config with defaults
|
|
if nargin == 1 && ~isempty(customConfig)
|
|
userFields = fieldnames(customConfig);
|
|
for i = 1:length(userFields)
|
|
defaultConfig.(userFields{i}) = customConfig.(userFields{i});
|
|
end
|
|
end
|
|
|
|
% Iterate and set properties
|
|
fields = fieldnames(defaultConfig);
|
|
for i = 1:length(fields)
|
|
try
|
|
set(groot, fields{i}, defaultConfig.(fields{i}));
|
|
catch ME
|
|
errorStruct.message = sprintf("%s\nUse get(groot, 'factory') " + ...
|
|
"to get all the available parameters.", ME.message);
|
|
errorStruct.identifier = ME.identifier;
|
|
errorStruct.stack = ME.stack;
|
|
error(errorStruct)
|
|
end
|
|
end
|
|
end |