MATLAB: Figure Sizing

Sizing your figures is critical to any publication or presentation. When I am attending a conference, there are few fundamental things that I despise more than not being able to read your figures! Fix it! If you are trying to convey useful information to me, then making it so I can read your figures is critical. From 30 feet away, your 12 pt comic sans selection means that I cannot tell the difference between [nm] and [mm]. Some might say that is a big difference, a mere 106.

…\rant

Ahem. Let me start again… Sizing your figures is critical to any publication or presentation. Figure are generally the first thing a reader sees in your paper. Figures convey your information and results during a presentation. If you are going to be an engineer, you a likely going to make a lot of figures in your career. You should get used to it. There are simple scripts that you can put together in MATLAB that simplify this process. MATLAB is almost infinitely flexible and there is almost nothing you cannot get a script to do for you in MATLAB. I am by no means a power user so putting together a good script to format figures is relatively simple. All it takes is a few steps.

Step 1: Consider the medium for which the figure is made

Whenever I make figures for manuscripts, presentations, or proposals, the first thing I do is consider the medium I am working with. Typically it is a single or two column format where there are size guidelines. These could be for figures in a paper or maximum margin widths in a proposal. Never make a figure that is arbitrarily sized. The key reason for this is that the text in the figures will be too small or too big compared with the rest of the figure. If you size the figure correctly from the start, you do not have to consider how text will shrink/expand. Therefore, e.g., if you use 10 pt font sizes for your axis labels, they will be printed at 10 pt font. The same goes for annotated text or other labels.

Step 2: Typical Width

If you are working in a two column journal, then most columns are 8 cm – 9 cm wide. If you are making a figure to fit in only one column, then check your journal formatting guidelines and make the figure no bigger than that size. I make all my single column figures 8.3 cm wide and this has worked well for me in the past.

If you are making a wider figure to span two column, then double it. If you are working with odd sized columns (I’m looking at you Optics Express and Optical Materials Express), then just make the figure the width of the column after determining the column width. However, sometimes I do not make it the maximum width of the full page because it can look very distorted. If that’s the case, I will make a few test figures, which only take a few seconds with the right script. Then I will how the figure appears in the page/presentation.

Step 3: Typical Height

The height of the figure can vary, which is why it is good to make a variable script in MATLAB (see below). Sometimes, I am plotting a simple data plot so it does not need to be that big. Other times, I have many different datasets that are offset for clarity, etc. This tends to make the figure taller. Usually, I start with 4 cm – 4.5 cm high for single column figure (in a two column format). Once I see what it looks like, I adjust from there. Also, for surface plots or pcolor plots in matlab, those tend to be square so the figures tend to be larger. But if you make a script to do this, then it becomes super easy to resize your figures.

Step 4: Axes & Other Content

Once you have made your figure box to the correct size, then you can start putting in your plots, axes, and other content. Make sure to set your font sizes appropriately for the content. Look for our other MATLAB tutorials on setting up axes correctly and printing the figure to file.


Matlab Script

Here is a MATLAB script you can use to create a figure box that has the desired figure number and size in units of centimeters. See below for code and comments. WordPress doesn’t like tabbed text so you may want to look at it in the MATLAB editor with the correct formatting. You can copy the text below or a script file is here: FigureSetup. It is a *.m-file for MATLAB but it is relabeled as a *.txt file because WordPress pitched a fit over uploading a *.m-file. If you use this file, save this file to your setup folder in Matlab (which is in your path) so that all of your files can have access to it even if this script is not in the folder. Then rename it to “FigureSetup.m” without the quotes. See below for usage.

function FigureSetup(FigNum,x_cm,y_cm)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Function ‘FigureSetup’:
%
% Establishes a Figure custom sized using units of centimeters for the
% width and height. This function is useful for generating figure boxes of
% custom size for publications. Note: figures may look distorted on the
% screen depending on your monitor and screen resolution. This function is
% intended for publications where the exact size of the figure is needed.
% This is meant to be used with the fuction ‘PrintRoutine’ to print the
% figure to a PNG file and an eps file.
%
% Typical Two-Column journal articles have a width of 8 cm to 9 cm. The
% height of the figure can vary based on the desired information.
%
% Input Variables:
%
% FigNum: a figure created with this figure number.
% x_cm: width of the figure in units of centimeters.
% y_cm: height of the figure in units of centimeters.
%
% System Defaults: If no figure number (FigNum) is specified, then a new
% figure will be created. If no X and Y dimensions are specified, then the
% figure size will default to x_cm = 8.3 and y_cm = 4.5 to create a figure
% that is 8.3 cm by 4.5 cm high.
%
% Written by Jonathan D. Ellis, PhD
% Updated August 26, 2015
% Version: 1.00
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M = nargin;

% Determine the number of input arguments
switch M
case {0}
figure;
x_cm = 8.3;
y_cm = 4.5;
case {1}
figure(FigNum)
x_cm = 8.3;
y_cm = 4.5;
case {2}
figure;
X = FigNum;
Y = x_cm;
x_cm = X;
y_cm = Y;
otherwise

figure(FigNum)
end

% initially position the figure in the center of the screen
set(gcf,’Units’,’normalized’,’Position’,[.33 .33 .33 .33])

% Set Figure units and orientation
set(gcf,’PaperUnits’,’Centimeters’,…
‘Units’,’Centimeters’,…
‘PaperOrientation’,’Portrait’,…
‘PaperPositionMode’,’auto’);

% Get the correctly scaled position vector (1×4) in units of centimeters.
% The figure should be placed at the 1/3rd – 1/3rd edge of the screen from
% the lower left corner
[A] = get(gcf,’Position’);

% Keep the same starting location for the figure box but now resize it to
% the input sizes
set(gcf,’Position’,[A(1) A(2) x_cm y_cm]);

% When printing the figure using the print command, it will print the
% figure to the default paper size (lettersize or A4). This part of the
% code resizes the paper of the figure such that it is the sam size as the
% figure. Now, when you print the figure to a file using the ‘print’
% command, it will be automatically cropped. For *.eps figures, this will
% create a bounding box at the edge of the figure.
PAPER = get(gcf,’Position’);
set(gcf,’PaperSize’,[PAPER(3) PAPER(4)])

end


Script Usage

This script is very simple to use. Once the file is in your path, test it out.

>> t=linspace(0,10,1000)’;
>> A = cos(2*pi*1*t);
>> FigureSetup(1,8.3,4)
>> plot( t , A )

You should get a figure that looks like this (if you printed it to file correctly. More on that in another tutorial.

FigureSetupExample

Now, this figure is not finished as it has no axis labels, for print it is not in a serif font, etc. But it is the start of setting up your figure. if you want to make it larger or smaller, then just change the “8.3,4” above. If you import this figure into Word/PowerPoint, it should be 8.3 cm by 4 cm (3.25 inches by 1.57 inches).

Try it out and let me know how it goes.