Matlab Fonts Not Rendering Correctly on Print or Export

瘦欲@ 提交于 2019-12-06 03:54:25

问题


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'])        

回答1:


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')


来源:https://stackoverflow.com/questions/16907573/matlab-fonts-not-rendering-correctly-on-print-or-export

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!