Skip to content

Instantly share code, notes, and snippets.

@MatteoRagni
Last active December 7, 2017 11:19
Show Gist options
  • Save MatteoRagni/a4a887599d9f34f47dfc4ad728f407e4 to your computer and use it in GitHub Desktop.
Save MatteoRagni/a4a887599d9f34f47dfc4ad728f407e4 to your computer and use it in GitHub Desktop.
Configuring Custom Default figure options in Matlab

Default Graphic Configuration

Installation

Check which is the startup file through the command:

which startup

and add in the same directory the included script 01_graphic_defaults.m. Add in the startup file the line

run 01_graphic_defaults

Configurations

  • always uses opengl as default renderer
  • set up figure position and dimension units to centimeters
  • set up the paper to a custom dimension (intead of a standard one)
  • set up dimensions for figure: 18cm width x 15cm width
  • set up dimensions for output paper: 18cm width x 15cm width
  • figure background color is white
  • figure fonts are all set to Palatino, with scaling for title fixed
  • grid are on by default, both on X and Y
  • for all text interpreter is set to LaTeX (thus rember to use $ to open/close math mode)

Exporting a figure

To show/export an image 10cm x 12cm use the following code:

figure('Position', [0, 0, 10, 12], 'PaperSize', [10, 12])
  scatter(0:99, rand(100,1));
  
  % Exporting command
  saveas(gcf, '02_figure.pdf');

This method guarantees that the dimension of the output file are consistent with the configuration.

% ___ __ _ _ ___ ___ ___ ___ _____
% | \ ___ / _|__ _ _ _| | |_ ___ / __| _ \/ _ \ / _ \_ _|
% | |) / -_) _/ _` | || | | _(_-< | (_ | / (_) | (_) || |
% |___/\___|_| \__,_|\_,_|_|\__/__/ \___|_|_\\___/ \___/ |_|
%% CELL OF ONFIGURATIONS
c = struct();
c.FigureRenderer = 'opengl';
c.FigureUnits = 'centimeters';
c.FigurePaperType = '<custom>';
c.FigurePosition = [0 0 18 15];
c.FigurePaperSize = [18 15];
c.FigureColor = 'w';
c.AxesFontName = 'Palatino';
c.TextFontName = c.AxesFontName;
c.LegendFontName = c.AxesFontName;
c.PolaraxesFontName = c.AxesFontName;
c.TextarrowshapeFontName = c.AxesFontName;
c.TextboxshapeFontName = c.AxesFontName;
c.ColorbarFontName = c.AxesFontName;
c.AxesTitleFontSizeMultiplier = 1.5;
c.PolaraxesTitleFontSizeMultiplier = 1.5;
c.LegendInterpreter = 'latex';
c.AxesTickLabelInterpreter = c.LegendInterpreter;
c.ColorbarTickLabelInterpreter = c.LegendInterpreter;
c.PolaraxesTickLabelInterpreter = c.LegendInterpreter;
c.TextInterpreter = c.LegendInterpreter;
c.TextarrowshapeInterpreter = c.LegendInterpreter;
c.TextboxshapeInterpreter = c.LegendInterpreter;
c.AxesXGrid = 'on';
c.AxesYGrid = 'on';
%% Setting Up... do not modify
fields = fieldnames(c);
for i = 1:length(fields)
prop = strcat('default', fields{i});
value = c.(fields{i});
fprintf(1, 'Setting %s to: %s\n', fields{i}, string(value));
set(groot, prop, value);
end
clear c fields i prop value
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment