Exporting figures from Matlab into Illustrator

Getting nice figures out of matlab is always a bit of a nightmare.
Here’s a few pretty simple steps I’ve adopted that work ok for my needs.

I use subplots quite a lot, and try to get my figures as close to publication ready in matlab (fixed axes, labels, scale bars in the right place, etc.) and then use plot2svg.m by  Juerg Schwizer which has two crucial properties:

  • It can export transparent (alpha) filled areas, which i use constantly for confidence bounds.
  • It will export images (image/imagesc) as separate PNGs which means no figures end up with some semi-corrupted/unrecoverable embedded image data.

Now the figures look something like this in illustrator:

Just opened the .svg in illustrator

Just opened the .svg in illustrator. There should be two subplots here, and axis labels.

There are no axis labels, and the other subplot is gone because there are incorrect clipping masks on objects. Also, selecting anything is a nightmare because objects are highly grouped with no particular rhyme or reason.

The solution is to remove all clipping masks and ungroup everything. This might need to be done for a few iterations recursively, and is a massive hassle to do manually. A while back I found out about a trick with an illustrator action that applies these steps a lot of times, and works in parallel on all selected objects.Now, the first thing to do after opening a .svg is to select all, and run this ‘kill it with fire’ action. When illustrator complains and asks if it should continue, this just means that parts of the stacks of nested objects have been run through, so keep clicking ‘continue’ a few more times just in case there’s other deeper nested stacks of objects.

Download illustrator action here

After killing the mess with fire.

After recursively ungrouping & removing all clipping masks.

After this step, all objects should be neat and separate and can be grouped /layered as needed. Sometimes, parts of plots will be missing – if that happens, it’s usually enough to reduce the number of simultaneous subplots.

This entry was posted in Matlab. Bookmark the permalink.

Comments are closed.