Exporting EPS Files from MATLAB with CMYK Colors

Most graphics exported from MATLAB, as said in a previous post, are of publishable quality, but some graphics require further editing to add more graphics elements. Unfortunately, EPS files with a CMYK model exported from MATLAB use a US color profile, not a ISO color profile. Import these files into Adobe Illustrator with a ISO set of color profiles, the colors are not displayed correctly. The following blog post explains the problem and provides a possible solution.

In 2014 MathWorks changed the default colormap of MATLAB from jet to parula. Steve Eddin’s blog about colormaps provides the history of the new colormap including the origin of the name. If you are interested in the history of the colors of MATLAB and the origin of the colormaps, you should have a look at the blog post of the MATLAB inventor and company founder Steve Molar, “The Origin of Colormaps“. The post also lists a number of valuable functions to display colormaps.

And yes, the 4th edition of the MRES book looks more beautiful with the new colors! Unfortunately, the print function with the -cmyk option does allow us to change the color standard from US to Europe. As an example let us create synthetic data using rand, display the data as a line plot and save the graphics as EPS files with CMYK and RGB colors.

clear, clc, close all
rng(0), data = rand(10,10);

We can then display the data as a line plot and save the graphics as EPS file with CMYK and RGB colors.

figure1 = figure('Position',[50 800 400 250]);
axes1 = axes('LineWidth',1.5,...
    'FontSize',14,...
    'Box','On'); hold on
line1 = line(1:10,data,...
    'LineWidth',2);
 
print -depsc2 -painters -cmyk figure1a_cmyk.eps
print -depsc2 -painters figure1a_rgb.eps

When we export the graphics using RGB colors, they are rendered correctly (left), while the colors using CMYK colors look differently (right). Similarly we can display the data as a surface plot and export as EPS files again.

figure2 = figure('Position',[50 450 400 250]);
axes2 = axes('Visible','Off',...
    'View',[-20 70]); hold on
surf2 = surf(data);

print -depsc2 -painters -cmyk figure2a_cmyk.eps
print -depsc2 -painters figure2a_rgb.eps

Again, when we export the graphics using RGB colors, they are rendered correctly (left), while the colors using CMYK colors look differently (right). Importing the files into Adobe Illustrator, as an example, applies the ISO color norm and the colors look different from what we expect from the original graphics in MATLAB. We can get the RGB and CMYK values in MATLAB using

for i = 1 : 7
    lcolor(i,:) = get(line1(i),'Color');
end
disp('Colormap of Line Plots')
cm_lines_rbg = uint8(255*lcolor)
cm_lines_cmyk = uint8(100*rgb2cmyk(lcolor))

which yields

cm_lines_rbg =
  0 114 189
217  83  25
237 177  32
126  47 142
119 172  48
 77 190 238
162  20  47

cm_lines_cmyk =
 74  29   0  26
  0  53  75  15
  0  24  80   7
  6  37   0  44
 21   0  49  33
 63  19   0   7
  0  56  45  37

Many steps are required to convert RGB to CMYK, as described by Steve Eddins in another blog post. The code above uses the function rgb2cmyk by C. Begler. Importing the same graphics with RGB colors, and then converting it into CMYK while importing it into Adobe Illustrator, I get the colors

 85  51   0   0
  9  78  98   1
  7  33  91   0
 62  92   0   0
 61   7  95   0
 63   5   0   0
 25  99  78  20

which seems to be the CMYK colors in ISO norm. The workaround is to export the EPS files as RGB files and then convert them to CMYK when importing the files into a vector graphics program like Adobe Illustrator. Perhaps a future version of MATLAB will allow us to export EPS files with CMYK color models using a ISO color profile in addition to a US color profile.