9

I'm having problems with rendering Greek characters in my labels and legends, so I thought maybe switching fonts would help. Thus, I discovered an even bigger problem - Matlab doesn't seem to honor my font settings at all.

I've tried, of course,

set(gcf, 'FontName', 'Ubuntu')
set(gca, 'FontName', 'Ubuntu')

but also things like

set(findall(gca, 'type', 'text'), 'FontName', 'Ubuntu')

and

set(0,'DefaultAxesFontName', 'Ubuntu')

I also tried switching renderers, with

set(0, 'DefaultFigureRenderer', 'OpenGL') % also tried 'zbuffer' and 'painters' 

I even went into property editor on the figure, and manually changed the fonts. Regardless of what I do, the font comes out with the same, ugly monospaced font (see figure below). This picture is saved with the Save As... command in the menu bar of the figure, but e.g. print -dpng 'fonttest.png' doesn't work either.

I've double-checked both with fc-list in my terminal, and listfonts at the Matlab command prompt, that the Ubuntu font is installed and available. I'm running Matlab R2012b.

How do I set the fonts in my figures?

UPDATE:
As suggested in comments, I tried to see if this is might be an issue with Java on Ubuntu. Sure enough, switching from OpenJDK to Oracle Java helped, but not enough - I can use Helvetica and a few others, but I can't choose freely among my installed fonts. The Ubuntu font, for example, does not work. (It does, however, in the main GUI of Matlab - there I've changed the fonts to Ubuntu in menus etc, and Consolas in the editor and command window, and it renders OK.)

Whenever I choose a figure font that doesn't work, Matlab uses what's shown in the screenshot below as fallback.

enter image description here

The p, q and f here should really be the greek letters pi, theta and phi (they're specified with \pi etc) but I guess the font doesn't have those characters. The weird stuff in the y-label of the third plot is a Swedish ö - it shouldn't be a problem with encodings, because the file is saved as UTF-8, which is also what slCharacterEncoding returns, so I assume that's also a font issue.

Community
  • 1
  • 1
Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • Might be related [missing fonts in Ubuntu for MATLAB](http://stackoverflow.com/a/16191865/2180721). Please post details of your OS. – Oleg Apr 25 '13 at 15:47
  • Also, try `uisetfont()` instead of `listfonts`. – Oleg Apr 25 '13 at 16:04
  • @OlegKomarov: Thanks for the link and hints - but installing the packages didn't help. Ubuntu is listed in the dialog that `uisetfont()` brings up, and selecting it does not change anything. I'm running Ubuntu 12.04. – Tomas Aschan Apr 25 '13 at 16:19
  • @TomasLycken: just to be clear, are you seeing this problem on the shown figures or the saved/exported images? – Amro Apr 25 '13 at 17:29
  • @Amro: Both - and I've tried exporting both with "File->Save As..." from the figure window, using `print -dpng 'test.png'` and using [`export_fig`](http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig). – Tomas Aschan Apr 25 '13 at 17:55
  • @TomasLycken: could this be an X11 issue? Perhaps you should cross-post on http://askubuntu.com/ – Amro Apr 26 '13 at 12:03
  • @Amro: Possible, but somehow it seems somewhat far-fetched to me. Anyway, I'm planning to upgrade to 13.04 within a couple of days, so I'll see if the problem persists. If it does, I might cross-post =) – Tomas Aschan Apr 26 '13 at 12:22
  • @TomasLycken: ok. One last idea, maybe this is a Java thing: http://askubuntu.com/questions/116782/why-do-fonts-look-horrible-in-any-java-application . Also worth seeing what `feature DefaultCharacterSet` and `feature locale` returns – Amro Apr 26 '13 at 12:36
  • @Amro: `feature DefaultCharacterSet` and `feature locale` both return UTF-8, as they should. However, I am running OpenJDK, which according to the post you linked to has some problems with fonts. I'm installing Oracle Java now, to see if it helps – Tomas Aschan Apr 26 '13 at 12:44
  • @Amro: Switching to Oracle Java 6 helped, *if* I also switch fonts to, say, Helvetica (there are a few others that work - most of my installed fonts don't). – Tomas Aschan Apr 26 '13 at 12:58
  • @TomasLycken: hmm i'm not sure, I assume you did set [MATLAB_JAVA](http://www.mathworks.com/support/solutions/en/data/1-1812J/) environment variable.. At least we've narrowed the problem down to Java :) – Amro Apr 26 '13 at 13:14
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28987/discussion-between-tomas-lycken-and-amro) – Tomas Aschan Apr 26 '13 at 14:59

2 Answers2

5

Installing xfonts-75dpi and xfonts-100dpi did the trick for me for the default settings.

sudo apt-get install xfonts-75dpi xfonts-100dpi

and then log out and log in again.

This seems to allow both symbols (e.g. \pi) and font size (e.g. set(h, 'FontSize', 14)) changes (using the default Matlab font).

Machine setup: Ubuntu 12.04 x64 with Matlab R2012b

benj
  • 303
  • 1
  • 12
1

Try using the option 'Interpreter', 'LaTex' (default is 'Interpreter', 'Tex'). This may get you to a less buggy font renderer.

Marc
  • 5,315
  • 5
  • 30
  • 36