Matlab Fonts Not Rendering Correctly on Print or Export
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 (ie 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'])
我使用imwrite命令而不是打印命令将数字转换为图像文件,但这不适用于EPS。
fhand = figure();
subplot(1,2,1);
...
I = getframe(fhand)
imwrite(I.cdata,'Inst.png','PNG')
链接地址: http://www.djcxy.com/p/33416.html