Matlab Fonts Not Rendering Correctly on Print or Export
Asked Answered
L

1

5

I'm trying to make a matlab figure that nicely fits into a LaTeX Document. A known problem is that the XTickLabel and YTickLabels do not render using the LaTeX interpreter, causing bad looking plots. (Note: I realize there are some fixes out there that involve replacing the tex labels with text objects (i.e. format_tics), however these solutions are non-trivial when plotting multiple figures, and come with problems of their own that require a lot of tweaking for each individual figure.)

I feel that approaching this problem through changing the font, as opposed to replacing objects in a figure, is a little more elegant.

I downloaded a .otf version of the LaTex font, and set that to display throughout the figure:

    set(0,'defaulttextinterpreter','latex')
    set(0,'DefaultTextFontSize', 10)
    set(0,'DefaultTextFontname', 'CMU Serif')
    set(0,'DefaultAxesFontSize', 10)
    set(0,'DefaultAxesFontName','CMU Serif')

Things look good in the matlab figure window; however when printing, things fall apart.

If i print (either using the export GUI or the print command) using the "painters" renderer, the fonts look funny and inconsistant throughout. Some symbols will not display correctly, and different fonts appear throughout the printed figure.

 print('-depsc','-painters',['InstP.eps'])        

If i switch to the zbuffer renderer, the fonts become consistant, but there are other bugs. The quality drops, and some text is left out (or covered by other text).

 print('-depsc','-zbuffer',['InstZ.eps'])  

The opengl is just a mess everywhere.

Does anybody know why these renders are having trouble with these fonts? And any work-arounds to get the fonts to render correctly?

Sample Code:

    subplot(1,2,1)
         imshow(IMG,'XData',XDat,'YData',YDat);
         axis image;axis([0 20 -5 5]);
         xlabel('$x^*$');
    subplot(1,2,2)
    imshow(SqImg,'XData',Xs,'YData',Xs);
    xlabel('$\Phi_B$');
    ylabel('$\Phi_A$');
    axis square;
    set(gca,'YDir','normal',...
            'XAxisLocation','bottom',... 
            'YAxisLocation','left',... 
         'XTick',(0:.5:1).^Exp,'XTickLabel',0:.5:1,...
         'YTick',(0:.5:1).^Exp,'YTickLabel',0:.5:1);


 print('-depsc','-painters',['InstP.eps'])        
 print('-depsc','-zbuffer',['InstZ.eps'])        
Libidinous answered 3/6, 2013 at 23:42 Comment(3)
I should note that I have the exact same problem with the Latin Modern Roman fontLibidinous
As a workaround, you could use plot2svg (mathworks.de/matlabcentral/fileexchange/…) to create *.svg files which can be easily converted to *.eps using IncScape or Adobe Illustrator.Broadleaf
Other workaround options from the File Exchange are export_fig and, since you're working with LaTeX, matlab2tikz. The latter of these solutions will allow your figures to truly fit in with the LaTeX fonts/environment.Pothouse
A
0

I use the imwrite command instead of the print command to turn the figures into image files, but this doesn't work with EPS.

fhand = figure();
subplot(1,2,1);
...
I = getframe(fhand)
imwrite(I.cdata,'Inst.png','PNG')
Alerion answered 12/6, 2013 at 17:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.