How to "Clean Up" a Matlab Figure with Adobe Illustrator

Overview

Basic process is as follows:

  1. Generate figure in Matlab

  2. Save figure to .eps format

    1. Ensure that renderer is set to Painters

  3. Open .eps figure with Illustrator

  4. Save as .pdf for Latex or .png for MS Word

Generate Figure in Matlab

It will be time-consuming to "clean up" figures in Illustrator, so spend some time in Matlab to make your figure look close to how you want it.

  • Size, aspect ratio

  • Title, axis labels, grid on, box off

  • Axis limits

  • Line colors, line style, line width

  • Legend

Save Figure to .eps

You can always click file>save as .eps in the figure window.

You can also use saveas() function in Matlab, e.g., if you want to save a bunch of figures:

%% Let's say you have 20 figures open that you would like to save.
%  Normally, these would have been generated by whatever program you are running.
%  But for the sake of demonstration, let's create 20 random plots.

numFigures = 20;
for i=1:numFigures 
    figure;
    plot(1:10,rand(1,10),'linewidth',1);
    xlabel('domain');
    ylabel('range');
    title(sprintf('This is figure %i',i));
end

%% Given that we have a number of open figures, 
%  we can save them and close them with this loop:
for i=1:numFigures
    h = figure(i); %Give the current figure a handle we can reference
    ax = gca; %Give the figure's axis a handle we can reference (gca stands for Get Current Axis)
    saveas(h,ax.Title.String,'eps'); %Save figure h with its title as its filename in the eps format
    close(h); %Close the figure
end

Matlab has multiple "renderers", which it uses to draw figures. The default is openGL. Sometimes, when you export a .eps using openGL, the result is bitmap-y. If you open it in illustrator, then we might need to change the renderer.

Default renderer can be changed with the command

set(0, 'DefaultFigureRenderer', 'painters');

Then resave the figure as .eps, and it should be editable in Illustrator.

Open .eps in Illustrator

Should see that figure is now made up of vectors. A couple weird things can happen.

  1. Your lines may be a whole bunch of tiny, unrelated points, which makes it hard to edit. Sometimes (I don't know why), lines are a "compound path" of many different points. Right click and "release compound path" to make it easier to edit.

  2. The font helvetica is Matlab's default, but isn't supported by Illustrator. Might be good to change font to Arial in Matlab before saving .eps.

Change the artboard to be the size that you want the figure on the page. For Living Machines papers, this is 12 cm (4.72 inches) wide. For other journals, you may want to make a full-column (6.5 inches wide) or half-column (3.25 inches wide) figure.

Move things around, adjust font sizes, transparencies, and other features that are hard to fix in Matlab.

In general, we don't want to change "the data"; don't shift, resize, smooth the plots.

Save as .pdf

.pdf is also a vector format, which Latex uses directly. If you are using Latex, then this is the way to do it.

Your figure .pdf may be very large. If it's 1 MB or larger, then it is too big. It will be difficult to email the figures around, and if you have a bunch of these in your paper, it will make the paper huge (like 10+ MB). This happens because each trace is preserved in the .pdf. If you have 1,000 lines, the .pdf saves them all, even if they all overlap. The solution is to downsample your data in Matlab before saving the .eps, or to not plot so many lines within the same figure. If this is truly unavoidable, then you can "flatten" the image in Illustrator, which basically converts it to a bitmap (from what I understand).

Save .png for MS Office

Ensure high resolution (600 dpi is typical).

If necessary, make the artboard transparent for background-less figures (very classy).

Last updated