MATLAB: font problems when exporting images using 'print'

If you have you ever tried to export a PNG or JPEG image via

print -dpng -r600 filename

or

print -djpeg -r600 filename

you have probably noticed that sometimes MATLAB does not correctly export the font (either font type, font size or both). The main reason for that is, that MATLAB uses "Helvetica" as default font which is not available at most/some linux systems. The painful thing :-( is that MATLAB does not complain but simply messes up the exported file. The solution is to use a different font, i.e. 'Dejavu Sans'. You can either change the fonts after creating the figures,

font = 'Dejavu Sans'; % set the same font everywhere
set(findobj('-property','FontName'), 'FontName', font);
set(get(gca,'xlabel'), 'FontName', font);
set(get(gca,'ylabel'), 'FontName', font);
set(get(gca,'title'), 'FontName', font);

or you change the default font by

set(0,'defaultAxesFontName', '<fontname>')
set(0,'defaultTextFontName', '<fontname>')

Then, hopefully, the problems with exporting bitmap graphics is gone... :-)

Tags

Operation System

Linux distribution (not cygwin)
deutsch english
Overview
Downloads
free game
SerpTrain
Physics Studies
Snippets
Mail Test
Guestbook
Contact
Valid HTML 4.01!
Valid CSS!
Get MySQL
Get PHP
Get Firefox
Get Thunderbird
© Michael "Serpedon" Walz